本文介绍了forEach 函数调用的调用上下文(this)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道 forEach 回调函数的this"值(或调用上下文)是什么.此代码似乎不起作用:
I was wondering what the 'this' value (or invocation context) is of the forEach callback function. This code doesn't seem to work:
var jow = [5, 10, 45, 67]; jow.forEach(function(v, i, a){ this[i] = v + 1; }); alert(jow);感谢向我解释.
推荐答案我完成了 forEach 方法的构建,想和大家分享这个图,希望它可以帮助其他人试图理解它的内部工作原理.
I finished construction of the forEach method and wanted to share this diagram with everyone, hope it helps someone else trying to understand its inner workings.
更多推荐
forEach 函数调用的调用上下文(this)
发布评论