【发布时间】:2020-08-15 09:56:17
【问题描述】:
这是我的代码、我的类、我的实例
语言:javascript
class People {
constructor (name) {
this.name = name
}
eat () {
console.log(`${this.name} eat something`)
}
}
class Student extends People {
constructor (name, number) {
super(name)
this.number = number
}
learn () {
console.log(`student ${this.name} is learning`)
}
}
class Teacher extends People {
constructor (name, major) {
super(name)
this.major = major
}
teach () {
console.log(`${this.name} teacher ${this.major}`)
}
}
// instance
const xialuo = new Student('xialuo-name', 100)
为什么我在 Chrome 中执行代码时会出现这种情况。
xialuo.__proto__.__proto__.__proto__.hasOwnProperty === Object.prototype.hasOwnProperty // true
Object.prototype.hasOwnProperty === xialuo.__proto__.__proto__.__proto__.hasOwnPerperty // false
发生了什么???
为什么上一行代码返回true。
下一行代码返回 false ???
我很困惑
【问题讨论】:
标签: javascript class google-chrome prototype proto