尝试理解下面的输出 - 为什么直接在对象上使用时检查是错误的 - 但是在实例上检查时为true?有人可以解释 - 我错过了什么吗?js中的构造函数
function Book2(){
this.title = "High Performance JavaScript";
this.publisher = "Yahoo! Press";
};
Book2.prototype.author = "hgghghg";
var b = new Book2();
alert(Book2.hasOwnProperty("title")); //false
alert(Book2.hasOwnProperty("toString")); //false
alert("title" in Book2); //false
alert("toString" in Book2); //true
alert(b.hasOwnProperty("title")); //true
alert(b.hasOwnProperty("toString")); //false
alert("title" in b); //true
alert("toString" in b); //true
*“为什么直接在对象上使用时检查是错误的 - 检查实例时是否为真”* - 实例*是*对象。函数是对象。原型也是一个对象。但它们不是同一个对象,并且它们并不都具有相同的属性。 – nnnnnn