日期:2014-05-16 浏览次数:20408 次
function ClassX(){ this.messageX = "This is the X message. "; if(typeof ClassX._initialized == "undefined"){ ClassX.prototype.sayMessageX = function(){ alert(this.messageX); }; ClassX._initialized = true; } } function ClassY(){ this.messageY = "This is the Y message. "; if(typeof ClassY._initialized == "undefined"){ ClassY.prototype.sayMessageY = function(){ alert(this.messageY); }; ClassY._initialized = true; } } function ClassZ(){ ClassX.apply(this); ClassY.apply(this); this.messageZ = "This is the Z message. "; if(typeof ClassZ._initialized == "undefined"){ // 使用zinherit工具包中的inheritFrom方法,实现多重继承,inferitFrom只会修改prototype的状态,而不会重新赋值 ClassZ.prototype.inheritFrom(ClassX); ClassZ.prototype.inheritFrom(ClassY); ClassZ.prototype.sayMessageZ = function(){ alert(this.messageZ); }; ClassZ._initialized = true; } } function myload(){ alert("cc"); var objZ = new ClassZ(); objZ.sayMessageX(); objZ.sayMessageY(); objZ.sayMessageZ(); }
objZ.instanceOf(ClassY); // return true