es 模組的基礎知識,深度瞭解

來源:互聯網
上載者:User

標籤:https   位置   div   let   name   field   bar   func   height   

// 一模組的基礎知識 /** * export :用於模組輸出的出口 * import :檔案引入的入口 */ // 1,第一種方式使用export方式輸出 var a = ‘a‘; var b = ‘v‘; export { a, b }; // 2,使用export作為預設值輸出 export { a as streamV1, b as streamV2 }; // 3,export 可以處於任何位置,只要頂端就可以, 不能處於塊級範圍 /** * import 檔案模組載入 */ // 1,直接模組載入 import { a, b } from ‘./ass‘; // 2,直接模組輸出 import * as cricle from ‘./ass‘ cricle.a // a /** * export default 預設輸出的命令,import模組載入,不需要{}模組載入 * */ // 1、匿名函數直接使用, import可以直接 模組載入,直接輸出名字 export default function () { console.log(‘foo‘); } import customName from ‘./export-default‘; // 2,直接輸出函數 function add(x, y) { return x * y; }
export { add as default } // 直接相當 export default add;
import { default as foo } from ‘./add‘; import foo from ‘./modules‘ /** * export 與 import 的複合寫法 */ export { foo, bar } from ‘./my_module‘; // 可以簡單理解為 import { foo, bar } from ‘./my_module‘; export { foo, bar }; // 二、匯出列表 export { detectCats, Kittydar }; // no `export` keyword required here function detectCats(canvas, options) { ... } class Kittydar { ... } // 三、重新命名匯出和匯入 import { flip as flipOmelet } from "eggs.js"; import { flip as flipHouse } from "real-estate.js"
function v1() { ... } function v2() { ... }
export { v1 as streamV1, v2 as streamV2, v2 as streamLatestVersion }; // 四、預設的匯入、匯出
import colors from "colors/safe"; export default { field1: value1, field2: value2 };
// 模組對象,像命名空間
import * as cows from "cows";
// 彙總模組,它不會在當前範圍中綁定將要匯出的變數 export { Tea, Cinnamon } from "sri-lanka";
/** * 深入理解 ES6 模組機制 https://zhuanlan.zhihu.com/p/33843378?group_id=947910338939686912 */

es 模組的基礎知識,深度瞭解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.