标签:log cli script asc let ++ -- this for循环
1、let在for循环中的应用
for(var i = 0; i < btn.length; i ++) { btns[i].onclick = function () { console.log(i) } }
for(var i = 0; i < btn.length; i ++) { btn[i].index = i; btns[i].onclick = function () { console.log(this.index) } }
-- 闭包
for(var i = 0; i < btn.length; i ++) { (function(i) { btns[i].onclick = function () { console.log(this.index) } })(i) }
-- let
for(let i = 0; i < btn.length; i ++) { btns[i].onclick = function () { console.log(i) } }
标签:log cli script asc let ++ -- this for循环
原文地址:http://www.cnblogs.com/nankeyimeng/p/7197758.html