1

hasOwnProperty search for __proto__ ?

 function Person(){}
 Person.prototype.name = "Nicholas";
 Person.prototype.age = 29;
 Person.prototype.job = "Software Engineer"; 
 Person.prototype.sayName = function(){

 };
 var person1 = new Person();
 person1.hasOwnProperty("name") // false ?

the above example comes from Prefessional JavaScript for Web Developers

use chrome : person1.hasOwnProperty("name") // is true

Dexygen
  • 12,287
  • 13
  • 80
  • 147
Lee.zm
  • 105
  • 1
  • 12

1 Answers1

1

Yes, it should be true.

person1.name = "Greg"; gives person1 its own name property, so it doesn't come via the prototype chain.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335