Skip to content

Loading…

Cascades in one closure get same varname #190

Closed
akx opened this Issue · 1 comment

2 participants

@akx
$('#something')
  &click !-> blah(&attr("foo"))

$('#somethingelse')
  &click !-> blah(&attr("bar"))

compiles to

var x$;
x$ = $('#something');
x$.click(function(){
  blah(x$.attr("foo"));
});
x$ = $('#somethingelse');
x$.click(function(){
  blah(x$.attr("bar"));
});

which causes problems with the first click handler's x$ referring to the second one due to lexical scope.

I know this could be easily circumvented with let but I still think this is counter-intuitive behavior.

Feel free to close if I'm wrong :)

@satyr
Owner

You're right. Apparently it shouldn't reuse the same variable.

@satyr satyr closed this in 3a85ac1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.