function a (){
this.testing = 'testing';
}
function b (){
}
b.prototype = new a();
console.log(b.testing);
控制台显示undefined,而不是“testing”。我做错了什么?
function a (){
this.testing = 'testing';
}
function b (){
}
b.prototype = new a();
console.log(b.testing);
你还没有创建 'b' 的实例。
var bInstance = new b();
console.log(bInstance.testing);
换句话说,原型的属性只出现在类型为 b
的对象上,而不是在 b()
构造函数本身上。