Javascript closures - variable scope question

前端 未结 5 1903
借酒劲吻你
借酒劲吻你 2020-11-28 13:15

I\'m reading the Mozilla developer\'s site on closures, and I noticed in their example for common mistakes, they had this code:

Helpful

5条回答
  •  旧巷少年郎
    2020-11-28 13:53

    Even if it's declared outside of the for loop, each of the anonymous functions will still be referring to the same variable, so after the loop, they'll all still point to the final value of item.

提交回复
热议问题