Skip to content

Instantly share code, notes, and snippets.

@mziwisky
Created December 6, 2016 20:38
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 mziwisky/8a15c708958e682da036e5a37d946166 to your computer and use it in GitHub Desktop.
Save mziwisky/8a15c708958e682da036e5a37d946166 to your computer and use it in GitHub Desktop.
unbinding of `this` for `import { x } from "y";` syntax
let foo = {
alpha () {
return this.bravo();
},
bravo () {
return "charlie";
}
}
export default foo;
import { alpha } from "foo";
alpha(); // Uncaught TypeError: Cannot read property 'bravo' of undefined
// webpack transpilation:
var _foo = __webpack_require__(3);
(0, _foo.alpha)();
// ================================
import foo from "foo";
foo.alpha(); // "charlie"
// webpack transpilation:
var _foo = __webpack_require__(3);
var _foo2 = _interopRequireDefault(_foo);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
_foo2.default.alpha();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment