問題描述
system.js 是否在我的 javascript 中添加內容? (Is system.js adding stuff to my javascript?)
我正在嘗試讓 JQWidgets 工作。它有一個 jsxcore.js 文件,該文件定義了以下變量:
var jqxBaseFramework = window.minQuery || window.jQuery;
然後在其他文件中,使用此變量。但是我收到一個錯誤,說 jqxBaseFramework is not defined
in the next file.
我注意到當我 system.import
一個文件時,這添加到它的頂部:
(function(require, exports, module, __filename, __dirname, global, GLOBAL) {
這會導致範圍內的變量超出範圍。
system.js 是這樣做的嗎?如果是這樣,是否有解決範圍問題的方法?
如果沒有,我將不得不將該變量添加到每個文件的頂部...。不好玩,因為有很多。
參考解法
方法 1:
Is system.js doing this?
Yes
If so, Is there a work around to the scope issue?
Yes. SystemJS is a module loading system. You treat your files as encapsulated modules. You should throw away the concept of globals.
Should you want to expose a value from a module, you export it. Should a module need a value from a certain module, you require it. Read more about CommonJS to know more about how this mechanism works.