SUMMARY
Objects are created and augmented at any point during code execution, making objects into dynamic, rather than strictly defined, entities. The following patterns are used for the creation of objects:
- The factory pattern uses a simple function that creates an object, assigns properties and methods, and then returns the object. This pattern fell out of favor when the constructor pattern emerged.
- With the constructor pattern, it's possible to define custom reference types that can be created using the
new
operator in the same way as built-in object instances are created. The constructor pattern does have a downside, however, in that none of its members are reused, including functions. Because functions can be written in a loosely typed manner, there's no reason they cannot be shared by multiple object instances. - The prototype pattern takes this into account, using the constructor's
prototype
property to assign properties and methods that should be shared. The combination...