1 ;(function(name, definition){ 2 //检测上下文环境是否为AMD或者CMD 3 var hasDefine = typeof define === ‘function‘, 4 //判断上下文是否为node 5 hasExports = typeof module !== ‘undefined‘ && module.exports; 6 7 if (hasDefine) { 8 //AMD环境或CMD环境 9 define(definition); 10 } else if (hasExports) { 11 //定义为普通node 模块 12 module.exports = definition(); 13 } else { 14 //将模块的结果挂在window变量中,this = window; 15 this[name] = definition(); 16 } 17 })(‘hello‘, function () { 18 var hello = function () {}; 19 return hello; 20 })
原文地址:https://www.cnblogs.com/yingquliang/p/9357326.html
时间: 2024-10-12 19:27:46