标签:对象 div class prope 存在 str string ISE OLE
<h3>判断某个属性是否存在于某个对象中;</h3> <ol> <li> in:检查一个属性是否属于某个对象,包括继承来的属性; <pre> var person = {name:‘yourname‘, age:10}; console.log(‘name‘ in person); //true console.log(‘sex‘ in person); //false console.log(‘toString‘ in person); //true </pre> </li> <li> hasOwnProperty():检查一个属性是否属于某个对象自有属性,不包括继承来的属性; <pre> var person = {name:‘yourname‘, age:10}; console.log(person.hasOwnProperty(‘name‘)); //true console.log(person.hasOwnProperty(‘sex‘)); //false console.log(person.hasOwnProperty(‘toString‘)); //false </pre> </li> <li> propertyIsEnumerable()是hasOwnProperty()的增强版: 检查一个属性是否属于某个对象自有属性,且该属性可枚举,不包括继承来的属性; <pre> var person = {name:‘yourname‘, age:10}; console.log(person.propertyIsEnumerable(‘name‘)); //true console.log(person.propertyIsEnumerable(‘sex‘)); //false console.log(person.propertyIsEnumerable(‘toString‘)); //false </pre> </li> </ol>
标签:对象 div class prope 存在 str string ISE OLE
原文地址:https://www.cnblogs.com/LeoXnote/p/9646463.html