Skip to content

Latest commit

 

History

History
37 lines (27 loc) · 696 Bytes

对象常用方法.md

File metadata and controls

37 lines (27 loc) · 696 Bytes

判断是否是对象自身的属性,而不是来自原型对象

可以使用hasOwnProperty()in操作符

let obj = {
    name:'flten'
}

let newObj = Object.create(obj, {
    age :{
        enumerable:true,
        configurable:true,
        writable:true,
        value:16,
    }
})

console.log(newObj.hasOwnProperty('name')) // false
console.log('age' in newObj) // true

instanceof 判断目标对象是否在该对象的原型链中

function Animal(){}

function Dog(){}

Dog.prototype = Object.create(Animal.prototype)

let dog = new Dog()
console.log(dog instanceof Animal) // true
console.log(dog instanceof Object) // true