function c1(name){ this.name=name; this.hello=function(){ console.log(this.name); }; } c2.prototype=new c1(); function c2(name){ var params=Array.prototype.slice.call(arguments); c1.apply(this,params); //将this传递给父类 } var obj1=new c1(‘zy‘) var obj2=new c2(‘zyy‘); obj2.hello() obj1.hello();
时间: 2024-09-29 00:53:17