Forked from brianleroux/default-transpiler-explainer.js
Created
February 26, 2015 18:17
-
-
Save developit/320a7930495f080806d7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Node style module writ in ES6 syntax: | |
export default foo = () => console.log(‘hi’) | |
// Unfortunately “literally” transpiles to this: | |
exports.default = function foo() { | |
return console.log(‘hi’) | |
} | |
// Which means this will fail: | |
var foo = require(‘./foo’) | |
foo() // object is not a function! | |
// But this will work: | |
var foo = require(‘./foo’).default | |
foo() // outputs 'hi' | |
// There is a fix! | |
// | |
// If we compile with 6to5 we get what we expect! | |
module.exports = function foo() { | |
return console.log(‘hi’) | |
} | |
// call as usual | |
var foo = require(‘./foo’) | |
foo() // outputs 'hi'! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment