js oo面向对象编程
昨天看JavaScript编程书籍,看到面向对象编程,js继承,说到有类式继承,原型继承,混合继承等,于是按照书中所说建立了一个继承辅助方法
function protend(child,super){
child.prototype = new super();//原型继承
}
function mixtend(child,super){
function __f() {
parent.call(this, child.arguments);
}
__f.prototype = new parent();
this.protend(child, __f);
__f = null;//删除中间类
}
}
//属性扩展。t为目标属性 s为原属性。b为是否覆盖
function attend(t,s ,b) {
for (var i in s) {
if ((i in t) && b) {
t["_" + i + "_"] = s[i];
} else {
t[i] = s[i];
}
}
}
function imptend(child,parent){
child.method = parent;
child.method();
delete child.method;}
//看了很多对象冒充继承的方法,但是还是不是很理解对象冒充具体的实现理论
上述方法都可以说完成继承功能,

浙公网安备 33010602011771号