在使用严格模式和确保能够在非 window 环境下运行的同时,你能否获取全局作用域?
看这些例子:
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`
// (https://dev59.com/mGox5IYBdhLWcg3wsGWC)
// But that not the point.
});
有没有办法在
define
内部获取全局变量(window
/GLOBAL
)?