Skip to content

Conversation

@apendua
Copy link

@apendua apendua commented Apr 23, 2013

I think it is a batter way to do it ;)

No instance of tha parent parent should be created here, since it is a premature stage. Imagine a generic manager class (this is exactlly the problem I had experienced), which specializes to some different kind of managers. To me, calling a manager constructor with no data attached did not make any sense, so using an instance of base class as a prototype of the child was not possilbe. Instead, one should use the prototype of the base class - that's what is it for.

@apendua
Copy link
Author

apendua commented Apr 23, 2013

If you're afraid to use Object.create (it's not supported in older versions of IE), you can always try this:

var f = function(){};
f.prototype = parent.prototype;
child.prototype = new f;

or even this ;)

child.prototype = { __proto__: parent.prototype };

These are all equivalents of

child.prototype = Object.create(parent.prototype);

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

Successfully merging this pull request may close these issues.

1 participant