object
es5的getPrototypeOf
getPrototypeOfes6中的setPrototypeOf
setPrototypeOfclass Person {
constructor() {
this.name = 'xiaocai'
}
}
class Child {}
p = new Person
c = new Child
console.log(p.name) // xiaocai
console.log(c.name) // undefined
console.log(c._proto_) // class Child
Object.getPrototypeOf(c) //constructor:class Child
// getPrototypeOf 就是利用的 _proto_
Object.setPrototypeOf(c, p)
Object.getPrototypeOf(c).constructor === Person // truegetPrototypeOf和setPrototypOf
getPrototypeOf和setPrototypOfsuper
call的误区
Last updated