猿问

来,把settimeout的代码改成我们想要的结果

constobj={
name:"jsCoder",
skill:["es6","react","angular"],
say:function(){
for(vari=0,len=this.skill.length;isetTimeout(function(){
console.log(i);
console.log(this.skill[i]);
}(i),0)
console.log(i);
}
}
};
obj.say();
改成settimeout中可以正常顺序打印i和依次打印skill,大家都懂的,有哪些方法,各位发挥
SMILET
浏览 388回答 2
2回答

四季花海

constobj={name:"jsCoder",skill:["es6","react","angular"],say:function(){this.skill.forEach(function(item,index){setTimeout(function(){console.log(index)console.log(item);},0)})},say2:function(){for(vari=0,len=this.skill.length;i

慕尼黑的夜晚无繁华

say:function(){varthat=this;for(vari=0,len=this.skill.length;i
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答