|
|
|
|
|
by Autre
5493 days ago
|
|
Well, I have to argue that it's not the same pattern. I think the problem
is that you still like to believe that js has classes, which it doesn't: js
has got objects only. That it also has constructor is an (admitted?)
historical mistake. Just think of all the weird crap that goes on to make
`new func()' work and produce a new object. What is no mistake is the refreshing change of view you get when you
start embracing objects and prototypal inheritance. See for example the
traits library[1, 2]. [3]: Is a cursory introduction to Self, with another points example :) [4] Contains an example of my own (heavily inspired by Self and Io). I have stitched together various internet
sources to come up with `clone', an operator assisting in differential
inheritance. [1]: http://traitsjs.org/ [2]: http://code.google.com/p/es-lab/source/browse/trunk/src/trai... [3]: http://www.cs.aau.dk/~bt/DAT5E08/MarkusKrogh1.pdf [4]: https://gist.github.com/997910 |
|
A factory is very different from a keyword baked into the language. The new keyword suggests that the underlying language is doing the construction, and all of the details about the object being created are encoded in its blueprint, "Point."
I consider a factory and a keyword to be two very different patterns regardless of whether you want to call them class-based or prototype-based.