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

wrong interpretation of "this" in prototype of Symbol #842

Closed
AndrewKovalenko opened this Issue Feb 20, 2015 · 1 comment

Comments

Projects
None yet
2 participants
@AndrewKovalenko

I try to extend prototype of Symbol class with my own methods:

Symbol.prototype.isBefore = Symbol.prototype.isBefore ||
(anotherSymbol) => {
  var self = this;
  var inMonadeInstance = new InMonade((collection) => {
    return collection.indexOf(self) < collection.indexOf(anotherSymbol);
  });

  return inMonadeInstance;
};

but after "compilation" to ES5 I receive

Symbol.prototype.isBefore = Symbol.prototype.isBefore || function (anotherSymbol) {
  var self = undefined;
  var inMonadeInstance = new InMonade(function (collection) {
    return collection.indexOf(self) < collection.indexOf(anotherSymbol);
  });

  return inMonadeInstance;
};

so any this are replaced with undefined

@kittens

This comment has been minimized.

Show comment
Hide comment
@kittens

kittens Feb 20, 2015

Member

No, this is correct behaviour. Arrow functions aren't interchangeable with normal functions.

Please see #814, #733 and #730.

Member

kittens commented Feb 20, 2015

No, this is correct behaviour. Arrow functions aren't interchangeable with normal functions.

Please see #814, #733 and #730.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.