I was setting up a little helper function like so:
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;
It is invoked like such:
function Foo(props) {
this.__(props); // or this.__construct(props);
...
}
var foo = new Foo({a:1,b:2,c:3});
As you can see, it just acts as a simple constructor. However when using it with EaselJS, specifically SpriteSheet()
I get an error of Uncaught TypeError: Cannot call method 'slice' of undefined
. Here is a snippet of code illustrating where the issue arises:
var ss = new SpriteSheet({
images: ...,
frames: {
...
},
animations: {
walk: [0, 1, "walk", 8] // <-- Error caused here.
}
});
So, is there a better way to go about writing an Object prototype like this, which will not cause a (presumably) clash with Easel? Or possibly a better way altogether? (Native?). Thanks.