3 ms·
I don't understand why this is being downvoted. The compiler's behavior is definitely wrong here, as you showed with your example. This issue could even come up
by walrus 15y ago
I don't understand why this is being downvoted. The compiler's behavior is
definitely wrong here, as you showed with your example. This issue could
even come up in practice. Suppose you have a checkbox with the id 'cb' in
your DOM. Consider the following script:
var list = [true, false, true, true, false];
document.getElementById('cb').onclick = function() {list.pop();};
When the checkbox is clicked, it should remove the last item in the list,
then put a checkmark into the box. Run this through the Js2coffee compiler
and you will get
list = [ true, false, true, true, false ]
document.getElementById("cb").onclick = -> list.pop()
Run this back through the CoffeeScript compiler to get: (modified slightly
for brevity)
var list = [true, false, true, true, false];
document.getElementById("cb").onclick = function() {return list.pop();};
Notice that it now returns the result of list.pop(). Since the last item in
the list is false, this will prevent the default browser behavior, so the
checkbox will not be checked when it is clicked the first time.