this & Object Prototypes by Kyle Simpson

this & Object Prototypes by Kyle Simpson

Author:Kyle Simpson
Language: eng
Format: epub, mobi, pdf
ISBN: 9781491904152
Publisher: O’Reilly Media, Inc.
Published: 2014-10-26T16:00:00+00:00


Note

If the function name identifier for Car.drive() hadn’t overlapped with (aka “shadowed”; see Chapter 5) Vehicle.drive(), we wouldn’t have been exercising method polymorphism. So, a reference to Vehicle.drive() would have been copied over by the mixin(..) call, and we could have accessed directly with this.drive(). The chosen identifier overlap shadowing is why we have to use the more complex explicit pseudopolymorphism approach.

In class-oriented languages, which have relative polymorphism, the linkage between Car and Vehicle is established once, at the top of the class definition, which makes for only one place to maintain such relationships.

But because of JavaScript’s peculiarities, explicit pseudopolymorphism (because of shadowing!) creates brittle manual/explicit linkage in every single function where you need such a (pseudo)polymorphic reference. This can significantly increase the maintenance cost. Moreover, while explicit pseudopolymorphism can emulate the behavior of multiple inheritance, it only increases the complexity and brittleness.

The result of such approaches is usually more complex, harder-to-read, and harder-to-maintain code. Explicit pseudopolymorphism should be avoided wherever possible, because the cost outweighs the benefit in most respects.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.