function test(){
var objA=new ClassA();
objA.sayColor();
var objB=new ClassB();
objB.color="blue";
objB.name="roboth";
objB.sayColor();
objB.sayName();
alert(objB instanceof ClassA);
alert(objB instanceof ClassB);
}
function ClassA(){}
ClassA.prototype.color="red";
ClassA.prototype.sayColor=function(){
alert(this.color);
};
function ClassB(){}
ClassB.prototype=new ClassA();
ClassB.prototype.name="roboth";
ClassB.prototype.sayName=function(){
alert(this.name);
}
prototype
最新推荐文章于 2022-04-25 10:52:24 发布