//完美的js继承 少了类管理器
Object.extend=function(){
var fnTest = /\b_super\b/;
//继承父类
var _super = arguments[0].prototype||this.prototype; var prototype=Object.create(_super) //初始化函数ctor
var _Class=function(){
if (this.ctor)
this.ctor.apply(this, arguments);
}
_Class.prototype = prototype; //当前类属性和方法
var prop = arguments[arguments.length-1];
for (var name in prop) {
var isFunc = (typeof prop[name] === "function");
var override = (typeof _super[name] === "function");
var hasSuperCall = fnTest.test(prop[name]); if (isFunc && override && hasSuperCall) {
prototype[name] = (function (name, fn) {
return function () {
var tmp = this._super;
this._super = _super[name];
var ret = fn.apply(this, arguments);
this._super = tmp;
return ret;
};
})(name, prop[name]);
} else {
prototype[name] = prop[name];
}
} //类继承
_Class.extend=Object.extend;
//类扩展
_Class.expand = function (prop) {
for (var name in prop) {
prototype[name] = prop[name];
}
};
return _Class }
var pointArray=Object.extend(Array,{
ctor:function(){
Array.prototype.push.apply(this,arguments)
} })
console.log(pointArray)
var arr=new pointArray(2,5) console.log(arr)
console.log(arr.push(4))