Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 374
orb Avatar asked Oct 05 '22 09:10

orb


1 Answers

[...] 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__.

like image 73
Felix Kling Avatar answered Oct 06 '22 22:10

Felix Kling