Skip to content

Instantly share code, notes, and snippets.

@sematgt
Created January 13, 2021 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sematgt/09581b6a2e24bf534cced780d66df090 to your computer and use it in GitHub Desktop.
Save sematgt/09581b6a2e24bf534cced780d66df090 to your computer and use it in GitHub Desktop.
/*
Differences & Limitations:
Does not have its own bindings to this or super, and should not be used as methods.
Does not have arguments, or new.target keywords.
Not suitable for call, apply and bind methods, which generally rely on establishing a scope.
Can not be used as constructors.
Can not use yield, within its body.
*/
// wrong
'use strict';
var obj = { // does not create a new scope
i: 10,
b: () => console.log(this.i, this),
c: function() {
console.log(this.i, this);
}
}
obj.b(); // prints undefined, Window {...} (or the global object)
obj.c(); // prints 10, Object {...}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment