orb orb - 3 months ago 8
Javascript Question

Prototypical inheritance without new or Object.create

Is there any way whatsoever to enable an object to inherit from a prototype (1) without using

new
, and
(2) without using
Object.create
. (I had a suspicion that new is present inside the
Object.create
method, but after the Firebug console told me it's native code, well, I have a suspicion it goes native.) When I say "inherit from a prototype" I mean real JavaScript prototypical inheritance (i.e, not just an imitation of it). I know real inheritance when I see it (i.e., the
__proto__
property is present, there is a circular reference between the constructor and the prototype, there is an inheritance hierarchy).

My question boils down to: even though 'we barely new ya', are the only two mechanisms for inheritance
new
and
Object.create
?

Answer

[...] are the only two mechanisms for inheritance new and Object.create?

Yes, they are. At least those are the only ones you should use.

You could directly assign to __proto__, but it is not a standard property yet. More info: MDN - __proto__.