Called on an object instance, accepts a string as argument. If the object has a property with the name contained in the string argument, it returns true
. Otherwise it returns false
.
在对象实例上调用,接受字符串作为参数。 如果对象具有名称包含在字符串参数中的属性,则它返回true
。 否则返回false
。
Example:
例:
const person = { name: 'Fred', age: 87 }
person.hasOwnProperty('name') //true
person.hasOwnProperty('job') //false
翻译自: https://flaviocopes.com/javascript-object-prototype-hasownproperty/