3 ms·
My feelings are that "new" is really what you want. If you're thinking, "I want to make a new point at 20, 100", you probably want to write: new Point(20,
by jashkenas 15y ago
My feelings are that "new" is really what you want. If you're thinking, "I want to make a new point at 20, 100", you probably want to write:
new Point(20, 100);
The problem in JS isn't the "new" keyword, it's how awkward and brittle prototypes are to create. You have to know to first define a constructor function (read "class object"), and then attach prototypal properties to it one at a time. If you intend to use the prototype chain for inheritance, you have to be even more careful, and bend over backwards to configure the prototype chain correctly, which requires the creation of a temporary intermediate function.
See later in this thread: http://news.ycombinator.com/item?id=2595128 http://news.ycombinator.com/item?id=2595128 ... nasty stuff. Verbose, fragile, and confusing.
This is why the ECMAScript committee is hard at work on proposals like these:
http://wiki.ecmascript.org/doku.php?id=strawman:classes http://wiki.ecmascript.org/doku.php?id=strawman:classes
http://wiki.ecmascript.org/doku.php?id=strawman:classes_as_inheritance_sugar http://wiki.ecmascript.org/doku.php?id=strawman:classes_as_i...
http://wiki.ecmascript.org/doku.php?id=strawman:classes_as_sugar http://wiki.ecmascript.org/doku.php?id=strawman:classes_as_s...
http://wiki.ecmascript.org/doku.php?id=strawman:classes_with_trait_composition http://wiki.ecmascript.org/doku.php?id=strawman:classes_with...
http://wiki.ecmascript.org/doku.php?id=strawman:classes_without_trait_composition http://wiki.ecmascript.org/doku.php?id=strawman:classes_with...