我假设有一些应用call
或apply
here 但我不确定如何实现它。
http://codepen.io/anon/pen/oXmmzo
a = {
foo: 'bar',
things: [1, 2, 3],
showFooForEach: function() {
this.things.map(function(thing) {
console.log(this.foo, thing);
});
}
}
a.showFooForEach();
假设我想要map
一个数组,但在函数中,我需要访问属于this
哪个foo
。在function
中map
创建一个新的this
背景,所以我显然需要coerse在某种程度上这种情况下回来了,但我怎么做,同时还具有访问thing
?