In Chrome Canary and Node.js 0.12.3, the following code prints p
.
'use strict';
let o = {
name: 'o',
foo: function() {
['1'].map(function() {
console.log(this.name);
}.bind(this));
},
};
let p = { name: 'p' };
o.foo.call(p); // p
In Chrome Canary the following code also prints p
. But why does it throw a TypeError in Node.js 0.12.3 with the --harmony
flag?
'use strict';
let o = {
name: 'o',
foo: function() {
['1'].map(() => {
console.log(this.name);
});
},
};
let p = { name: 'p' };
o.foo.call(p); // p in Chrome, TypeError in Node.js with --harmony
Put another way, why is this
undefined
when the second code snippet is run in Node.js?