【发布时间】:2012-01-12 03:01:42
【问题描述】:
我正在查看store.js 的源代码,特别是它如何将自身添加到全局范围:
if (typeof module != 'undefined') { module.exports = store }
else if (typeof define === 'function' && define.amd) { define(store) }
else { this.store = store }
我理解最后一条this.store = store,但是其他的呢? module 和 define 函数是什么? this.store = store 不是已经可以在所有浏览器上运行了吗?
更一般地说,将模块添加到全局范围的正确跨浏览器方式是什么?
【问题讨论】:
标签: javascript module-pattern global-scope self-invoking-function