scope of variables in JavaScript callback functions

前端 未结 5 934
野的像风
野的像风 2020-12-01 06:51

I expected the code below to alert \"0\" and \"1\", but it alert \"2\" twice. I don\'t understand the reason. Don\'t know if it is a problem of jQuery. Also, please help me

5条回答
  •  没有蜡笔的小新
    2020-12-01 07:25

    It appears that you've created a closure inside your loop The Mozilla Developers Reference has a good section about this.

提交回复
热议问题