Open Tonyhark opened 9 years ago
下面这段代码及注释思考了很久还是不太明白,这里判断this.constructor === SubClass 具体的用途是什么。 什么情况下 this.constructor !== SubClass? this.constructor === SubClass 又意味着什么? 请大神赐教 // Only call initialize in self constructor. if (this.constructor === SubClass && this.initialize) { this.initialize.apply(this, arguments) }
function Parent(){} function Child(){} Child.prototype = new Parent(); console.log(new Child().constructor); // function Parent(){}
这意味着prototype的不谨慎赋值将影响constructor的查找。
下面这段代码及注释思考了很久还是不太明白,这里判断this.constructor === SubClass 具体的用途是什么。 什么情况下 this.constructor !== SubClass? this.constructor === SubClass 又意味着什么? 请大神赐教 // Only call initialize in self constructor. if (this.constructor === SubClass && this.initialize) { this.initialize.apply(this, arguments) }