Skip to content

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

Closed

Description

@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

Activity

  1. sebmck commented on Feb 20, 2015

    @sebmck
    Contributor

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

    Please see #814, #733 and #730.

  2. added
    outdated
    on Jul 31, 2018
  3. locked as resolved and limited conversation to collaborators on Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    outdated

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions