Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arrow functions' lexical binding is not working correctly #735

Closed
smfoote opened this issue Feb 5, 2015 · 4 comments
Closed

Arrow functions' lexical binding is not working correctly #735

smfoote opened this issue Feb 5, 2015 · 4 comments

Comments

@smfoote
Copy link

smfoote commented Feb 5, 2015

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.

var obj = {
  init: function() {
    this.handle(this.cb);
  },
  cb: val => {
    console.log(this.val);
    console.log(val);
    return val + this.val;
  },
  handle: function(cb) {
    console.log(cb(3));
  },
  val: 5
};

console.log('calling cb directly');
console.log(obj.cb(3));
// 5
// 3
// 8

console.log('calling cb via init');
obj.init();
// undefined
// 3
// NaN
@phpnode
Copy link

phpnode commented Feb 5, 2015

@smfoote this is a V8 bug, the arrow function implementation in the current V8 is not spec compliant and shouldn't be used. If you want/need such features, you'll have to use something like 6to5 for now.

@bnoordhuis
Copy link
Member

@smfoote A general observation: if you have to pass a flag to enable a language feature in V8, the feature isn't stable yet.

@smfoote
Copy link
Author

smfoote commented Feb 6, 2015

Thanks, all. I was simply trying to help by pointing out that the feature is not yet up to spec. I won't submit any other issues for features hidden by flags.

@bnoordhuis
Copy link
Member

@smfoote That's appreciated. :-) Most things V8 are not under our direct control, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants