jQuery .each() function with ES6 arrow functions [duplicate]
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: $('elems').each() with fat arrow 2 answers I have this ES6 code, after I compile it with Babel to ES5 the this inside .each 's call back becomes undefined . How do I fix this problem? let mediaBoxes = $(".now-thumbnail"); let titles = []; mediaBoxes.each(() => { let obj = { index: i, title: $(this).find(".now-thumbnail-bottomtext").text().trim() }; titles.push(obj); }); 回答1: My solution is to not use this at all, but use the variables that are passed to the callback function. The first one is the