Array.prototype.map()需要第二个参数来设置
this在映射函数中引用的内容,因此将其
this作为第二个参数传递以保留当前上下文:
someList.map(function(item) { ...}, this)另外,您可以使用ES6 箭头功能自动保留当前
this上下文:
someList.map((item) => { ...})
Array.prototype.map()需要第二个参数来设置
this在映射函数中引用的内容,因此将其
this作为第二个参数传递以保留当前上下文:
someList.map(function(item) { ...}, this)另外,您可以使用ES6 箭头功能自动保留当前
this上下文:
someList.map((item) => { ...})