【发布时间】:2015-01-27 10:30:21
【问题描述】:
我研究了 JavaScript 中的继承和 OOPS。我创建了“A”对象和“B”对象,并将“B”的所有属性继承到“A”。
当我使用“instanceof”检查新创建的对象实例时,我发现两个对象都是真的。
但我只使用“B”构造函数创建了对象。
function A(){
this.a = "test1",
this.b = "test2"
}
function B(){
this.c = "test3",
this.d = "test4"
}
B.prototype = new A();
var userObj = new B();
console.log(userObj instanceof B); // true
console.log(userObj instanceof A); // true, How this can be true?
【问题讨论】:
标签: javascript oop inheritance