本文共 1203 字,大约阅读时间需要 4 分钟。
阿里内部一小部分人在用,已经卖给国外了。所以使用并不是很广泛,作为前端开发,了解即可。
它同样是用于浏览器端的模块化规范,模块加载也是异步的。
模块使用时才会加载执行。
|-js |-libs |-sea.js |-modules |-module1.js |-module2.js |-module3.js |-module4.js |-main.js|-index.html
define(function (require, exports, module) { //内部变量数据 var data = 'atguigu.com' //内部函数 function show() { console.log('module1 show() ' + data) } //向外暴露 exports.show = show})
define(function (require, exports, module) { module.exports = { msg: 'I Will Back' }})
define(function (require, exports, module) { const API_KEY = 'abc123' exports.API_KEY = API_KEY})
define(function (require, exports, module) { //引入依赖模块(同步) var module2 = require('./module2') function show() { console.log('module4 show() ' + module2.msg) } exports.show = show //引入依赖模块(异步) require.async('./module3', function (m3) { console.log('异步引入依赖模块3 ' + m3.API_KEY) })})
define(function (require) { var m1 = require('./module1') var m4 = require('./module4') m1.show() m4.show()})
转载地址:http://oavii.baihongyu.com/