2 ms·
Could you please state the reasons for this change: 'cannot return a value from a constructor'. Besides breaking working code, this feels more like an added res
by arvidkahl 14y ago
Could you please state the reasons for this change: 'cannot return a value from a constructor'. Besides breaking working code, this feels more like an added restriction than an added feature. I'd love to know why this is in 1.5. Thanks!
- jashkenas 14y agoIt 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()