嗯..楼上说得对....
这是一个不太标准的继承
他不是在类上进行继承,而是对类的对像进行了掺元类式的复制~
var Extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
}
function Class1 (){
this.c1 = 'test1';
this.c2 = 'test2';
this.c3 = function (){alert("I am func c3");};
}
Class1.prototype.c4 = function (){alert("I am func c4");};
function Class2 (){
this.c5 = 'test5';
this.c6 = 'test6';
}
var oClass1 = new Class1();
var oClass2 = new Class2();
Extend(oClass2,oClass1);
//这里的参数不是类,而是类的实例~
oClass2.c4();
alert(oClass2.c5);