ES5的闭包用ES6怎么实现

如何将下面的代码用es6的let实现,

for(var i = 0; i < 3;i++) {

    (function(j){

        $.ajax({

            url: 'xxx',

            success: function(){

                console.log(j);

            }

        })(i);

    })

}


慕斯王
浏览 766回答 1
1回答

神不在的星期二

for(let i = 0; i < 3;i++) {&nbsp; &nbsp; &nbsp; &nbsp; $.ajax({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; url: 'xxx',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; success: function(){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log(i);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; };&nbsp; &nbsp; &nbsp; &nbsp; });}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript