Skip to content

Instantly share code, notes, and snippets.

@mziwisky

mziwisky/foo.js

Created Dec 6, 2016
Embed
What would you like to do?
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
You can’t perform that action at this time.