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

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

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
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.

@kittens kittens closed this Feb 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment