您可以在使用嚴格模式時獲得全局作用域,並確保您可以在非窗口環境中運行。如何在定義函數中獲取全局作用域?
參見這些例子:
define(['other', 'thing'], function() {
// this === window in desktop environment
// this === GLOBAL in node environment
});
define(['other', 'thing'], function() {
"use strict";
// this === undefined in desktop environment
// this === GLOBAL in node environment
// As of my understanding node has to be configured using `node --use_strict`
// (http://stackoverflow.com/questions/9031888/any-way-to-force-strict-mode-in-node)
// But that not the point.
});
有什麼辦法進去define
全局變量(window
/GLOBAL
)。
可能重複:http://stackoverflow.com/q/8280137/783743 –