Speaking JavaScript by Axel Rauschmayer

Speaking JavaScript by Axel Rauschmayer

Author:Axel Rauschmayer
Language: eng
Format: epub, pdf
Tags: COMPUTERS / Programming Languages / JavaScript
ISBN: 9781449364984
Publisher: O’Reilly Media
Published: 2014-02-23T16:00:00+00:00


function StrictColor(name) { 'use strict'; this.name = name; } var c = StrictColor('green'); // TypeError: Cannot set property 'name' of undefined

Returning arbitrary objects from a constructor

In many object-oriented languages, constructors can produce only direct instances. For example, consider Java: let’s say you want to implement a class Expression that has the subclasses Addition and Multiplication. Parsing produces direct instances of the latter two classes. You can’t implement it as a constructor of Expression, because that constructor can produce only direct instances of Expression. As a workaround, static factory methods are used in Java:



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.