JavaScript の「export default」とは何ですか? 質問する

JavaScript の「export default」とは何ですか? 質問する

ファイル:セーフストリング

// 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

ベストアンサー1

これはES6モジュールシステムの一部であり、ここで説明このドキュメントには役立つ例も記載されています:

モジュールがデフォルトのエクスポートを定義する場合:

// foo.js
export default function() { console.log("hello!") }

中括弧を省略すると、デフォルトのエクスポートをインポートできます。

import foo from "foo";
foo(); // hello!

更新: 2015年6月現在、モジュールシステムは次のように定義されています。§15.2特に構文exportは次のように定義されています。§15.2.3ECMAScript 2015 仕様の。

おすすめ記事