关于js hasOwnPropetry // instanceof 整理
hasOwnPropetry ()
Object的hasOwnProperty
()方法返回一个布尔值,判断对象是否包含特定的自身(非继承)属性。function foo() {
this.name = 'foo'
this.sayHi = function () {
console.log('Say Hi')
}
}
foo.prototype.sayGoodBy = function () {
console.log('Say Good By')
}
let myPro = new foo()
console.log(myPro.name) // foo
console.log(myPro.hasOwnProperty('name')) // true
console.log(myPro.hasOwnProperty('name1')) // false
console.log(myPro.hasOwnProperty('sayGoodBy')) // false
console.log('sayGoodBy' in myPro) // true
instanceof
instanceof用于判断一个变量是否某个对象的实例,
myPro instanceof foo //true foo instanceof Object //true myPro instanceof Object //true
可以判断数组 对象类型
let arr=[1,2,3];
let obj= {name:'姓名',value:23}
arr instanceof Array // true
obj instanceof Array // false

浙公网安备 33010602011771号