天天看点

Javascript继承之对象冒充法

例如:有三个类classX,classY,classZ

classZ分别继承classX和classY

于是就有下面的写法:

function ClassZ(){

this.newMethod=classX;

this.newMethod();

delete this.newMethod;

this.newMethod=classY;

this.newMethod();

delete this.newMethod;

}

这种写法存在一个弊端.。如果classX和classY有具有同名的属性或方法。classy具有高优先级。

继续阅读