That will actually pass map as this. Basically, here's how this works in JavaScript:
| Invocation type | Syntax | this value |
| function | fn(arg); | global object1 |
| method | obj.fn(arg); obj["fn"](arg); | obj |
| apply | fn.call(self, arg); fn.apply(self, argArray); obj.fn.call(self, arg); | self |
| bind2 | var f = fn.bind(thing); f(arg); var f = obj.fn.bind(thing); f(arg); | thing |
It does not matter what happened prior to the invocation; e.g.
var fn = obj.fn;
fn(1, 2, 3);
will behave as the first invocation pattern. Another example:
fn(1, 2, 3); // `this` is the global object (see footnote 1)
obj.fn = fn;
obj.fn(1, 2, 3); // `this` is obj
obj.fn is exactly equivalent to and is merely syntactic sugar for obj["fn"].
- Behavior changed in ECMAScript 5 strict mode. this value will be undefined if "use strict" is active. c.f. ES5 Appendix C
- Requires ECMAScript 5 or an equivalent polyfill.