首頁 > web前端 > js教程 > 主體

什麼是「export default」以及它與「module.exports」有何不同?

DDD
發布: 2024-10-17 23:01:29
原創
228 人瀏覽過

What is \

ES6's "export default" Explained

JavaScript's ES6 module system introduced "export default," a unique way of defining a default export for a module.

In the example provided, the file SafeString.js defines a SafeString class and exports it as the default export using:

export default SafeString;
登入後複製

This default export can be imported from another module by using the following syntax:

import SafeString from './SafeString.js';
登入後複製

Equivalent Syntax

Before ES6, there was no direct equivalent to "export default." However, a similar approach could be achieved using "module.exports:"

module.exports = SafeString;
登入後複製

This would assign the SafeString class to the module object, allowing other modules to access it.

以上是什麼是「export default」以及它與「module.exports」有何不同?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:php
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!