Created
December 6, 2016 20:38
-
-
Save mziwisky/8a15c708958e682da036e5a37d946166 to your computer and use it in GitHub Desktop.
unbinding of `this` for `import { x } from "y";` syntax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let foo = { | |
alpha () { | |
return this.bravo(); | |
}, | |
bravo () { | |
return "charlie"; | |
} | |
} | |
export default foo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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