Skip to content

Instantly share code, notes, and snippets.

@LeezQ
Created February 27, 2015 05:45
Show Gist options
  • Save LeezQ/4226d6187a945be1530c to your computer and use it in GitHub Desktop.
Save LeezQ/4226d6187a945be1530c to your computer and use it in GitHub Desktop.
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();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment