What is "export default" in JavaScript?
ecmascript-6, javascript, node.js
Solution
It's part of the ES6 module system, described here. There is a helpful example in that documentation, also:
If a module defines a default export:
// foo.js
export default function() { console.log("hello!") }
then you can import that default export by omitting the curly braces:
import foo from "foo";
foo(); // hello!
Update: As of June 2015, the module system is defined in §15.2 and the `export` syntax in particular is defined in §15.2.3 of the ECMAScript 2015 specification.
Problem
File: SafeString.js ``` // Build out our basic SafeString type function SafeString(string) { this.string = string; } SafeString.prototype.toString = function() { return "" + this.string; }; export default SafeString; ``` I have never seen `export default` before. Are there any equivalent stuff for `export default` that can be easier to understand?