欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript面向?qū)ο缶幊檀a

 更新時(shí)間:2011年12月19日 23:42:53   作者:  
javascript面向?qū)ο缶幊檀a,學(xué)習(xí)js面向?qū)ο缶幊痰呐笥芽梢詤⒖枷隆?/div>
復(fù)制代碼 代碼如下:

var orchard = function (){ //基類型構(gòu)造函數(shù)代理 靜態(tài)方法都在代理函數(shù)上
this.constructor && this.constructor.apply(this,arguments);
};
orchard.extend = function() {
var parentObj = this;
var parameters = parentObj.parameters ?
parentObj.parameters.concat(_.toArray(arguments)) : _.toArray(arguments);
var thisObj = function(){ //繼承類型構(gòu)造函數(shù)代理
var newparameters = parameters.concat(_.toArray(arguments));
this.constructor && this.constructor.apply(this,newparameters);
};
_.extend(thisObj,parentObj);
_.extend(thisObj.prototype,parentObj.prototype);
thisObj.parameters = parameters;
thisObj.base = thisObj.prototype.base = parentObj; //基類型的代理函數(shù)
thisObj.supper = thisObj.prototype.supper = parentObj.prototype; //基類型的構(gòu)造函數(shù) 類成員都在構(gòu)造函數(shù)上
return thisObj;
};
orchard.define = function(object){
if(typeof object === "undefined") object = {constructor: function(){}};
this.prototype = object.constructor;
this.prototype.constructor = this.prototype;
for(var name in this.base)
if(typeof this[name] === "undefined")
this[name] = this.base[name];
for(var name in this.supper)
if(typeof this.prototype[name] === "undefined")
this.prototype[name] = this.supper[name];
for(var i = 0; i < arguments.length; i++)
_.extend(this.prototype,arguments[i]);
this.prototype.base = this.base;
this.prototype.supper = this.supper;
this.supper = undefined;
delete this.supper;
return this;
};
orchard.definenew = function(){
var newclass = this.extend();
return define.apply(newclass,arguments);
};

調(diào)用:
復(fù)制代碼 代碼如下:

var Person = orchard.definenew({
constructor: function(name){
this.name = name;
},
say: function(){ return "Hello, i'm " + name;}
});
var aBen = Person.extend("aBen");
aBen.define({
constructor: function(){
this.supper.apply(this,arguments);
}
});
var aben = new aBen();
alert(aben.say());

思路就是這樣的,代碼沒(méi)驗(yàn)證過(guò)。分享的思路,大家自己看著辦。哈哈~~

相關(guān)文章

最新評(píng)論