Skip to content

需要使用Array.isArray(obj)来判断变量是否为数组 #12

@tiaod

Description

@tiaod
C3D.create = function (obj) {
        var _obj;
        switch (typeof(obj)) {
            case 'array':
                _obj = {type: 'sprite', children: obj};
                break;
            case 'object':
                _obj = obj;
                break;
            default:
                return;
        }

        return createObj(_obj);
    };

这段代码里面使用了typeof(obj)来判断是否为数组。事实上typeof([])返回的是'object'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions