对象原型干扰Easeljs

时间:2012-11-09 20:05:41

标签: javascript prototype easeljs

我正在设置一个小帮手功能:

if (!Object.prototype.__construct) {
Object.prototype.__construct = function() {
    if (typeof arguments[0] !== 'object' ||
        arguments.length === 0) return;
    for (var name in arguments[0]) {
        if (arguments[0].hasOwnProperty(name))
            this[name] = arguments[0][name];
    }
}}

if (!Object.prototype.__)
    Object.prototype.__ = Object.prototype.__construct;

它被调用如下:

function Foo(props) {
    this.__(props); // or this.__construct(props);
    ...
}
var foo = new Foo({a:1,b:2,c:3});

正如您所看到的,它只是一个简单的构造函数。但是当与EaselJS一起使用时,特别是SpriteSheet()我得到Uncaught TypeError: Cannot call method 'slice' of undefined的错误。以下是一段代码,说明问题出现的地方:

var ss = new SpriteSheet({
    images: ...,
    frames: {
        ...
    },
    animations: {
        walk: [0, 1, "walk", 8] // <-- Error caused here.
    }
});

那么,是否有更好的方法来编写像这样的Object原型,这不会导致(可能)与Easel的冲突?或者可能是一个更好的方式? (原生?)。感谢。

0 个答案:

没有答案
相关问题