4 ms·
> would be nice for 'academic' reasons if the compiler translated js->cs perfectly You should expect this from a compiler, actually > In my opinion, js functi
by fooyc 15y ago
> would be nice for 'academic' reasons if the compiler translated js->cs perfectly
You should expect this from a compiler, actually
> In my opinion, js functions should always return a value
Sounds wrong
> real code example of where your program would fail because of this?
Simple:
// That's perfectly fine; why would I return anything from this ?
link.onclick = function() {
doSomething();
};
// Now, translated in coffeescript:
link.onclick = ->
return doSomething(); // if this returns false, the "click" event is canceled
- fooyc 15y agoAn other good example is constructors; say you have a function like this: function MyClass(x){ this.x = x; } In Coffeescript this translates to MyClass = (x) -> @x = x `x` is returned; and if you return something from a constructor, something is returned instead of the constructed object (`new MyClass({})` returns `{}`).