The arrow function is supposed to bind to the scope in which it is defined (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), and the this of an arrow function should not be able to change. As shown in the code below (run with the --harmony_arrow_functions), the arrow functions are not correctly binding.
varobj={init: function(){this.handle(this.cb);},cb: val=>{console.log(this.val);console.log(val);returnval+this.val;},handle: function(cb){console.log(cb(3));},val: 5};console.log('calling cb directly');console.log(obj.cb(3));// 5// 3// 8console.log('calling cb via init');obj.init();// undefined// 3// NaN
The arrow function is supposed to bind to the scope in which it is defined (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), and the
thisof an arrow function should not be able to change. As shown in the code below (run with the--harmony_arrow_functions), the arrow functions are not correctly binding.