通用的Javascript模块规范共有两种,CommonJS和AMD。
【CommonJS主要在服务端】
node.js的模块化规范就是参照CommonJS规范进行实现的,node.js内部开放全局api,require(),用于加载模块,例如阮老师的例子:
let math = require('math'); math.add(2,2); // 4
CommonJS本质上是同步的加载的,由于服务端文件在本地,IO读取速度极快,并且会常驻,所以同步完全满足要求。
【AMD主要在浏览器端】
由于浏览器要加载大量的远程Js,并且要支持异步模型,因此CommonJS的规范不满足要求,因此推出AMD规范,AMD就是异步模块定义的缩写。再来一个阮老师的例子
require([module], callback);
require(['math'], function (math) { math.add(2, 3); });
window.setInterval(method,time)方法本身会返回一个资源句柄,使用clearInterval(Intervalid)方法即可清除定时器<script> var num=0; //每隔1秒再控制台输...
https://3gimg.qq.com/lightmap/v1/marker/index.html?marker=coord:37.6767600000,112.7297800000&key=TKUBZ-D24AF-GJ4JY-JDVM2-IBYKK-KEBCU&referer=p...
<!DOCTYPE html> <html> <head> <title>捕捉和冒泡</title> <meta charset="utf-8"> </head> <bo...
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> </head> ...
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>获取mac地址</title> </head&g...
代码1:<!--代码开始--> <script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script> <script>...