C
cbare
Hello JS Gurus,
One thing I haven't figured out about javascript is the treatment of
__proto__.
Inheritence, whether prototypes or class-based, is just a shorthand
form of delegation (leaving aside dynamic dispatch).
In Java a derived class serves as a wrapper for its superclass. The
derived class can easily access members of its super class using the
nice "super" keyword. Why, in javascript, is this functionality buried
in the unofficial "__proto__" property? It seems that it must have
been the intent of the language designer that explicitly accessing the
prototype chain is a bad thing for some reason, although I can't see
any reason.
By googling, you can find a lot of weird hacks to add "super"-like
functionality to javascript, although many of them look misguided to
me. It certainly seems that this is a commonly confusing part of the
language.
If __proto__ were an official part of the language, implementing a
decorator or proxy pattern would be nicely simplified compared to
class-based inheritence. The "before-and-after" style of AOP (which is
just another style of shorthand for delegation) would be possible
without any crazy tricks.
So, anyone care to set me straight? Why isn't __proto__ or something
like it a well defined part of javascript? Shouldn't it be??
Thanks,
-chris
One thing I haven't figured out about javascript is the treatment of
__proto__.
Inheritence, whether prototypes or class-based, is just a shorthand
form of delegation (leaving aside dynamic dispatch).
In Java a derived class serves as a wrapper for its superclass. The
derived class can easily access members of its super class using the
nice "super" keyword. Why, in javascript, is this functionality buried
in the unofficial "__proto__" property? It seems that it must have
been the intent of the language designer that explicitly accessing the
prototype chain is a bad thing for some reason, although I can't see
any reason.
By googling, you can find a lot of weird hacks to add "super"-like
functionality to javascript, although many of them look misguided to
me. It certainly seems that this is a commonly confusing part of the
language.
If __proto__ were an official part of the language, implementing a
decorator or proxy pattern would be nicely simplified compared to
class-based inheritence. The "before-and-after" style of AOP (which is
just another style of shorthand for delegation) would be possible
without any crazy tricks.
So, anyone care to set me straight? Why isn't __proto__ or something
like it a well defined part of javascript? Shouldn't it be??
Thanks,
-chris