AMD&CMD 兼容实现

Reading time ~1 minute

AMD&CMD 兼容实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(function(name,definition){ 
//兼容 AMD CMD
//AMD 定义了 define 函数,我们可以使用 typeof 探测该函数是否已定义。
//若要更严格一点,可以继续判断 define.amd 是否有定义
var hasDefine = typeof define === 'function'&& define.cmd,
//对于 CommonJS,可以检查 exports 或是 module.exports 是否有定义。
hasExports = typeof module !== 'undefined' && module.exports;
 if(hasDefine){ 
 	define(definition) 
 }else if(hasExports){
 	module.exports = definition();
 }else{ //把对象放到window里
 	this[name] = definition();
 }
})("m9futil",function(){
//严格模式
'use strict';
var m9futil = {};
//TODO 
return m9futil;
});

Git命令

Published on April 29, 2016

我的地盘

Published on April 18, 2016