system.js 是否在我的 javascript 中添加內容? (Is system.js adding stuff to my javascript?)


問題描述

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.

(by VaccanoJoseph)

參考文件

  1. Is system.js adding stuff to my javascript? (CC BY‑SA 2.5/3.0/4.0)

#systemjs #javascript #jqwidget






相關問題

使用 System.js 處理 css 導入的 React 組件的 Mocha 測試 (Mocha test of React component which uses System.js to handle css import)

TypeScript 和 systemjs 循環依賴 (TypeScript and systemjs circle dependency)

TypeScript 系統模塊未註冊導入的文件位置 (TypeScript system modules not registering imported file locations)

如何在帶有 SystemJS 的 TypeScript 中使用 momentjs? (How to use momentjs in TypeScript with SystemJS?)

在子目錄中運行 Angular2 (Running Angular2 In Subdirectory)

System.import 加載模塊但不執行其中的任何代碼 (System.import loading module but not executing any code within it)

無法加載 AngularJS 2 路由器 (Can't load AngularJS 2 router)

打字稿模塊和 systemjs。從內聯腳本實例化類 (Typescript modules and systemjs. Instantiate class from inline script)

材料 2 - 如何讓 md-icon 在 SystemJS 項目中工作? (Material 2 - how to let md-icon work in SystemJS project?)

myFile.js 檢測為註冊但未執行 (myFile.js detected as register but didn't execute)

條件加載 Angular2 (Conditional load Angular2)

使用 SystemJS 將 Angular 2 升級到 Angular 7 (Upgrade Angular 2 with SystemJS to Angular 7)







留言討論