我正在查看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
不会已经适用于所有浏览器了吗?
更一般地说,如何正确跨浏览器添加模块到全局作用域中?