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?
export default function(){}
can be used when the function has no name. There can only be one default export in a file. The alternative is a named export.This page describes
export default
in detail as well as other details about modules that I found very helpful.export default
is used to export a single class, function or primitive from a script file.The export can also be written as
This is used to import this function in another script file
Say in app.js, you can
A little about export
As the name says, it's used to export functions, objects, classes or expressions from script files or modules
Utiliites.js
This can be imported and used as
App.js
Or
When export default is used, this is much simpler. Script files just exports one thing. cube.js
and used as App.js
It's part of the ES6 module system, described here. There is a helpful example in that documentation, also:
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.As explained on this MDN page
For example: