↑ 封装类必不可少的东西
另外还有一个问题,在没有createjs的环境下也能使用这些oop的api吗,答案是可以的,我还特意把相关代码提取了出来,只要把下面的代码放入项目中,不引入createjs,也能使用oop的api
this.oop = this.oop||{};
oop.extend = function(subclass, superclass) {
function o() {
this.constructor = subclass;
}
o.prototype = superclass.prototype;
return (subclass.prototype = new o());
};
oop.promote = function(subclass, prefix) {
var subP = subclass.prototype,supP = (Object.getPrototypeOf&&Object.getPrototypeOf(subP))||subP.__proto__;
if (supP) {
subP[(prefix+="_") + "constructor"] = supP.constructor; // constructor is not always innumerable
for (var n in supP) {
if (subP.hasOwnProperty(n) && (typeof supP[n] == "function")) { subP[prefix + n] = supP[n]; }
}
}
return subclass;
};
就这么简单的2个方法……