Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何理解判断this.constructor === SubClass? #17

Open
Tonyhark opened this issue Feb 11, 2015 · 1 comment
Open

如何理解判断this.constructor === SubClass? #17

Tonyhark opened this issue Feb 11, 2015 · 1 comment

Comments

@Tonyhark
Copy link

下面这段代码及注释思考了很久还是不太明白,这里判断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)
}

@seanpan
Copy link

seanpan commented Sep 11, 2015

function Parent(){}
function Child(){}
Child.prototype = new Parent();
console.log(new Child().constructor); // function Parent(){}

这意味着prototype的不谨慎赋值将影响constructor的查找。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants