什么是“导出默认值”在javascript? [英] What is "export default" in javascript?
问题描述
档案: SafeString.js
//构建我们的基本的SafeString类型
函数SafeString(string){
this.string = string;
}
SafeString.prototype.toString = function(){
return+ this.string;
};
导出默认SafeString;
之前从未见过 export default
是否有任何等价的东西, export default
X-4545 X-4545 X-45 X-454545 X-454545 X-454545 X-454545 X-454545 X-454545 X-454545 X-454545 X- 20045 X-4545 X-4545 X-新评新新新旗新新新新旗新新旗旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗旗新新旗新新旗旗新200新新新新旗新新旗200新新新旗200新新新新旗200新新新新旗200新新新新旗新新旗2001-新新新新新新旗新新旗2001-新新新新新新旗新新旗2001-新新新新新旗新新旗2001-新新新新新旗新新旗2001-新新新新新新新新新旗2001-新新新新新新旗新新款: b $ b
模块foo{
export default function(){console.log(hello!)}
}
< X- 20045454545 X- 20045 X-454545 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 200 X- pre> import foo fromfoo;
foo(); // 你好!
更新:截至2015年2月2日,模块系统定义在§15.2.3。当然,由于它仍然是草案,这可能会在将来发生变化。
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?
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:
module "foo" { 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 February 2, 2015, the module system is defined in §15.2 and the export
syntax in particular is defined in §15.2.3 of the ES6 draft specification. Of course, since it's still a draft, this may change in the future.
这篇关于什么是“导出默认值”在javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!