javascript除call函式外實現繼承的方式之一
阿新 • • 發佈:2019-02-16
function x(n){
this.name=n;
this.show=function(){
alert(this.name);
}
}
function y(n){
this.__proto__=new x(n);
this.constructor=y;
}
var s=new y("李四");
this.name=n;
this.show=function(){
alert(this.name);
}
}
function y(n){
this.__proto__=new x(n);
this.constructor=y;
}
var s=new y("李四");
s.show();
function u(n){
this.name=n;
this.show=function(){
alert(this.name);
}
}
function v(n){
u.call(this,n);
this.constructor=v;
}
var k=new v("王五");
alert(k.constructor);