javascript模組化簡單解析,javascript模組化

來源:互聯網
上載者:User

javascript模組化簡單解析,javascript模組化

本文為大家解讀javascript的模組化,具體內容如下

AMD是RequireJS在推廣過程中對模組定義的正常化產出。

非同步載入模組,依賴前置,提前執行。
Define定義模組 define([‘require','foo'],function(){return});
Require載入模組(依賴前置) require([‘foo','bar'],function(foo,bar){});

CMD是SeaJS在推廣過程中對模組定義的正常化產出。

Define定義exports 匯出define(function(require,exports,module){});  module上儲存了當前模組上的一些對象。
require(./a)直接引入。Require.async非同步引入。
同步載入,依賴就近,順延強制。 

SeaJS 的應用

官方入門例子:http://seajs.org/docs/#quick-start

怎麼寫一個SeaJS模組?

// 所有模組都通過 define 來定義define(function(require, exports, module) {  // 通過 require 引入依賴 var $ = require('jquery'); var Spinning = require('./spinning');  // 通過 exports 對外提供介面 exports.doSomething = ...  // 或者通過 module.exports 提供整個介面 module.exports = ... });

在頁面中載入模組

//在 hello.html 頁尾,通過 script 引入 sea.js 後,有一段配置代碼: // seajs 的簡單配置seajs.config({ base: "../sea-modules/", alias: {  "jquery": "jquery/jquery/1.10.1/jquery.js" }}) // 載入入口模組seajs.use("../static/hello/src/main")

以上就是關於javascript模組化的簡單介紹,希望對大家學習javascript模組化有所協助。

您可能感興趣的文章:
  • Javascript模組化編程(一)模組的寫法最佳實務
  • Javascript模組化編程(一)AMD規範(規範使用模組)
  • Javascript模組化編程(三)require.js的用法及功能介紹
  • JavaScript的模組化:封裝(閉包),繼承(原型) 介紹
  • javascript模組化是什麼及其優缺點介紹
  • Javascript模組化編程詳解
  • 深入探尋seajs的模組化與載入方式
  • JavaScript模組化開發之SeaJS

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.