hasOwnProperty 表示 : 是否有自己的属性。
这个方法 : 会查找一个 { 对象 } 是否有某个属性 ,
但是 不会 去查找它的 原型链 。
▍示例
var obj = {
a: 1,
fn: function(){ },
b:{
c: 5
}
};
console.log(obj.hasOwnProperty('a')); // true
console.log(obj.hasOwnProperty('fn')); // true
console.log(obj.hasOwnProperty('b')); // true
console.log(obj.b.hasOwnProperty('c')); // true
console.log(obj.hasOwnProperty('c')); // false, obj 对象没有 c 属性
var str = new String();
// split 方法是 String 这个对象的方法,str 对象本身是没有这个 split 这个属性的
console.log(str.hasOwnProperty('split')); // false
console.log(String.prototype.hasOwnProperty('split')); // true