JavaScript原型继承


function A(){
  this.fa = function(){
    console.log("function in A");
  }
}
function B(){
  this.fb = function(){
    console.log("function in B");
  }
}
var a = new A();
a.fa();//function in A
var b = new B();
// b.fa(); //throw error;
b.fb(); //function in B
console.log(b instanceof A) //false
B.prototype = new A();
var b = new B();
b.fa(); //function in A
b.fb(); //function in B
console.log(b instanceof A)//true
console.log(b instanceof B)//true

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注