标签:alert pre rip property 访问 prototype 操作 str sof
in操作符只要通过对象能访问到属性就返回true。hasOwnProperty()只在属性存在于实例中时才返回true。
function Person(){ } Person.prototype.name = "Nicholas"; Person.prototype.age = 29; Person.prototype.job = "Software Engineer"; Person.prototype.sayName = function(){ alert(this.name); }; var person1 = new Person(); var person2 = new Person(); alert(person1.hasOwnProperty("name"));//false alert("name" in person1);//true person1.name = "Greg"; alert(person1.name);//"Greg" alert(person1.hasOwnProperty("name"));//true alert("name" in person1);//true delete person1.name; alert(person1.name);//"Nicholas" alert(person1.hasOwnProperty("name"));//false alert("name" in person1);//true
javascript中in和hasOwnProperty区别
标签:alert pre rip property 访问 prototype 操作 str sof
原文地址:http://www.cnblogs.com/cag2050/p/6068010.html