1

Possible Duplicate:
How does JavaScript .prototype work?

Here is the inheritance structure I setup for testing:

function A() {
    this.a = 1;
}

function B() {
    this.b = 2;
}

B.prototype = new A();
//B.prototype.constructor = B;

Below is what I tried in Chrome's JavaScript Console:

>var b = new B;
>b instanceof A
true

>B.prototype.constructor
function A() {
    this.a = 1;
}

My question is what's the purpose to setup B.prototype.constructor = B? Which I've already commented out? It doesn't seem to break the inheritance.

Thanks in advance.

1

1 Answer 1

0

B.prototype.constructor = B results in instanceof' giving the expected results, but there are better ways of doing that. There is some discussion of this at: Convention for prototype inheritance in JavaScript

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.