码迷,mamicode.com
首页 > 其他好文 > 详细

兼容node、amd、cmd规范

时间:2018-07-23 23:35:25      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:兼容   init   on()   win   hasd   exports   判断   pre   mod   

 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 })

 

兼容node、amd、cmd规范

标签:兼容   init   on()   win   hasd   exports   判断   pre   mod   

原文地址:https://www.cnblogs.com/yingquliang/p/9357326.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!