7 ms·
It is a restriction, and I'm a bit torn about it. Apart from fixing bugs where you'd use a CoffeeScript `class` to extend from a native object, returning "othe
by jashkenas 14y ago
It is a restriction, and I'm a bit torn about it.
Apart from fixing bugs where you'd use a CoffeeScript `class` to extend from a native object, returning "other" values from a constructor is a bad idea because it makes your code lie.
widget = new Widget
In CoffeeScript 1.5+, unless you go to great lengths to get around it, that's always going to return a new Widget -- in JavaScript, that could return a Dongle, an old and already used Widget, or anything else (that's not a primitive). If you want a function that maybe returns a new Widget, and maybe an old one, just use a normal function, not a constructor:
widget = Widget.lookup()