2 ms·
> Here's a simple example: http://jsfiddle.net/63fUY/ http://jsfiddle.net/63fUY/ . Hah. Fun one. > And it would be so easy to avoid if the language had a synt
by masklinn 14y ago
> Here's a simple example: http://jsfiddle.net/63fUY/ http://jsfiddle.net/63fUY/ .
Hah. Fun one.
> And it would be so easy to avoid if the language had a syntax for "default to no return" which we could just use on all event handlers.
Alternatively, rollback the "implicit return" but make the explicit return short and sweet yet still visible. E.g. use Smalltalk's unary `^` (which as far as I know currently exists neither in JS nor in CS) so the callbacks would be:
->
totalClicks++
$('#total').text totalClicks
^false # explicitly return false
and
->
$('#state').text if nextState then "On" else "Off"
nextState = !nextState
# no explicit return -> undefined as in JS