跳过正文

javascript 原型链

·36 字·1 分钟
jiladahe1997
作者
jiladahe1997
To see the world as it is, and to love it

原型链 继承 instanceof总结
#

原型链:

IMG_20191009_214712_1.jpg

instanceof:

object instanceof constructor

instanceof 运算符用来检测 constructor.prototype 是否存在于参数 object 的原型链上。

继承:

主要注意在inhreits函数中:

subclass.prototype = Object.create(superclass.prototype,{constructor:subclass})的作用等于:

subclass.prototype = {constructor:subclass}

subclass.prototype.__proto__ = superclass.prototype

然而:在一般情况下,subclass.prototype .constructor = subclass

因此理论上来说:只需要subclass.prototype.__proto__ = superclass.prototype即可完成最简单的继承

另外:

subclass._proto__=superclass的作用是在79行: 进行super的继承

QQ截图20191009215123.png

QQ截图20191009215131.png