通用的Javascript模块规范共有两种,CommonJS和AMD。
【CommonJS主要在服务端】
node.js的模块化规范就是参照CommonJS规范进行实现的,node.js内部开放全局api,require(),用于加载模块,例如阮老师的例子:
let math = require('math');
math.add(2,2); // 4CommonJS本质上是同步的加载的,由于服务端文件在本地,IO读取速度极快,并且会常驻,所以同步完全满足要求。
【AMD主要在浏览器端】
由于浏览器要加载大量的远程Js,并且要支持异步模型,因此CommonJS的规范不满足要求,因此推出AMD规范,AMD就是异步模块定义的缩写。再来一个阮老师的例子
require([module], callback);
require(['math'], function (math) {
math.add(2, 3);
}); https://3gimg.qq.com/lightmap/v1/marker/index.html?marker=coord:37.6767600000,112.7297800000&key=TKUBZ-D24AF-GJ4JY-JDVM2-IBYKK-KEBCU&referer=p...
<!-- 三个核心方法 openDatabase:这个方法使用现有数据库或创建...
<!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8"> </head> <body>...
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body>...
开发需求如下,商品下单后需要指定送到日期:送达日期为周一 周三 周六 ,如果今天周一,用户选择周一即为下一周周一。代码如下:<html> <head> <meta charset="utf-8"> <title>...
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> </head> ...