JavaScript原型链

2018-03-28  本文已影响0人  不要升级win10
image.png
微信截图_20180603163324.png
class Person{
    constructor(name){
        this.name = name
    }
}

class Student extends Person {
    constructor(name, id) {
        super(name)
    }
}

console.log(p.__proto__ === Person.prototype)
console.log(s.__proto__ === Student.prototype)
console.log(Student.prototype.__proto__ === Person.prototype)//true
console.log(Student.prototype.constructor === Student)

JS没有类,只有键值对组成的数据
普通对象的__proto__属性指向该实例的构造函数的原型对象,s.__proto__ === Student.prototype
原型对象的__proto__属性指向父构造函数的原型对象,Student.prototype.__proto__ === Person.prototype
class Person的本质是个函数

image.png
1.png
上一篇 下一篇

猜你喜欢

热点阅读