Created
February 27, 2015 05:45
-
-
Save LeezQ/4226d6187a945be1530c to your computer and use it in GitHub Desktop.
commonjs 和 amd 规范封装事例代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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