3 ms·
Some people think that library consumers shouldn't have to use new. Instead they should call a factory function (which itself calls new).
by MatthewPhillips 14y ago
Some people think that library consumers shouldn't have to use new. Instead they should call a factory function (which itself calls new).
- phleet 14y agoHere's an argument in favor of not requiring library consumers to use new by the author of the Raphäel library: http://dmitry.baranovskiy.com/post/something-new http://dmitry.baranovskiy.com/post/something-new
- orangecat 14y agoAnd I agree with that. "new" exposes too much implementation detail: it always allocates an object, and it's exactly the type specified, neither of which callers should normally care about. I much prefer how Python does it.
- ufo 14y agoActually, in Javascript you can preemptively return a value of a different type from the constructor instead of relying on the implicit `return this` at the end. That said, I agree that the way "new" specifies the concrete type of the returned value is pure evil. In OO things should be typed according to their interfaces, not according to their concrete implementations.