commonjs 和 amd 规范封装事例代码
(function(factory){
//判断客户端还是服务端
var isWindow = ( typeof window !== 'undefined' ? true : false );
var global = ( isWindow ? window : this );
if (typeof module !== 'undefined' && module.exports) {
module.exports = factory();
}
// AMD RequireJS
else if (typeof define !== 'undefined' && define.amd) {
define('myPlugin', [], factory() );
}
else if(isWindow){
window.myPlugin = factory();
}
})(function(global){
/*
* myPlugin 代码
*/
return _myPlugin();
});