博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CMD:SeaJS模块化教程
阅读量:4094 次
发布时间:2019-05-25

本文共 1203 字,大约阅读时间需要 4 分钟。

sea.js简单使用教程

阿里内部一小部分人在用,已经卖给国外了。所以使用并不是很广泛,作为前端开发,了解即可。

它同样是用于浏览器端的模块化规范,模块加载也是异步的。

模块使用时才会加载执行。

  1. 下载sea.js, 并引入
  • 官网: http://seajs.org/
  • github : https://github.com/seajs/seajs
  • 将sea.js导入项目: js/libs/sea.js
  1. 创建项目结构
|-js  |-libs    |-sea.js  |-modules    |-module1.js    |-module2.js    |-module3.js    |-module4.js    |-main.js|-index.html
  1. 定义sea.js的模块代码
  • module1.js
    define(function (require, exports, module) {  //内部变量数据  var data = 'atguigu.com'  //内部函数  function show() {    console.log('module1 show() ' + data)  }  //向外暴露  exports.show = show})
  • module2.js
    define(function (require, exports, module) {  module.exports = {    msg: 'I Will Back'  }})
  • module3.js
    define(function (require, exports, module) {  const API_KEY = 'abc123'  exports.API_KEY = API_KEY})
  • module4.js
    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)  })})
  • main.js : 主(入口)模块
    define(function (require) {  var m1 = require('./module1')  var m4 = require('./module4')  m1.show()  m4.show()})
  1. index.html:

转载地址:http://oavii.baihongyu.com/

你可能感兴趣的文章
Java的时间操作玩法实例若干
查看>>
JavaScript:时间日期格式验证大全
查看>>
pinyin4j:拼音与汉字的转换实例
查看>>
XML工具代码:SAX从String字符串XML内获取指定节点或属性的值
查看>>
时间日期:获取两个日期相差几天
查看>>
责任链模式 Chain of Responsibility
查看>>
高并发与大数据解决方案概述
查看>>
解决SimpleDateFormat线程安全问题NumberFormatException: multiple points
查看>>
MySQL数据库存储引擎简介
查看>>
处理Maven本地仓库.lastUpdated文件
查看>>
Kafka | 请求是怎么被处理的?
查看>>
Java并发编程1-线程池
查看>>
CentOS7,玩转samba服务,基于身份验证的共享
查看>>
计算机网络-网络协议模型
查看>>
计算机网络-OSI各层概述
查看>>
Java--String/StringBuffer/StringBuilder区别
查看>>
mySQL--深入理解事务隔离级别
查看>>
分布式之redis复习精讲
查看>>
数据结构与算法7-栈
查看>>
线性数据结构学习笔记
查看>>