什么是“出口默认"?在 JavaScript 中? [英] What is "export default" in JavaScript?
本文介绍了什么是“出口默认"?在 JavaScript 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
// Build out our basic SafeString type
function SafeString(string) {
this.string = string;
}
SafeString.prototype.toString = function() {
return "" + this.string;
};
export default SafeString;
我以前从未见过export default
.export default
是否有更容易理解的等效内容?
I have never seen export default
before. Are there any equivalent stuff for export default
that can be easier to understand?
推荐答案
它是 ES6 模块系统的一部分,在此处描述.该文档中还有一个有用的示例:
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!
更新:截至 2015 年 6 月,模块系统定义在 §15.2 和 export
语法在 §15.2.3.
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.
这篇关于什么是“出口默认"?在 JavaScript 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文