December 2016
Intermediate to advanced
841 pages
17h
English
As JavaScript is a prototype-based programming language, you might be using prototype related patterns all the time without knowing it.
We've talked about an example in the Abstract Factory Pattern, and part of the code is like this:
class FreightRocketFactory
implements RocketFactory<FreightRocket> {
createRocket(): FreightRocket {
return new FreightRocket();
}
}
Sometimes we may need to add a subclass just for changing the class name while performing the same new operation. Instances of a single class usually share the same methods and properties, so we can clone one existing instance for new instances to be created. That is the concept of a prototype.
But in JavaScript, with the prototype concept built-in, new Constructor() does basically ...
Read now
Unlock full access