for a in [1,2,3]
$('body').click (x) =>
alert a
It alerts 3 three times when I click the body. I would like it to alert 1, 2, and 3.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I screwed up the syntax the first time, but got it right this time:
You need to create a closure around the function and call it immediately (much like you would in Javascript). Coffeescript even gives you a nice syntax to do that for you… the do keyword: