-
Notifications
You must be signed in to change notification settings - Fork 8
EnvironmentDetection
uupaa edited this page Oct 25, 2015
·
30 revisions
それぞれの環境における特徴点を洗い出したものが以下になります。
| typeof * | Browser | Worker | Node | NW.js | Electron render |
Electron main |
|---|---|---|---|---|---|---|
| window | object | - | - | object | object | - |
| self | object | object | - | object | object | - |
| global | - | - | object | object | object | object |
| GLOBAL | - | - | object | - | object | object |
| document | object | - | - | object | object | - |
| process | - | - | object | - | - | - |
| WorkerLocation | - | object | - | - | - | - |
| __dirname | - | - | string | - | string | string |
| __filename | - | - | string | - | string | string |
| setTimeout + "" | native | native | custom | native | native | custom |
var GLOBAL = (this || 0).self || global;
// --- environment detection -------------------------------
// https://github.com/uupaa/WebModule/wiki/EnvironmentDetection
GLOBAL.IN_EL = !/undefined/.test(typeof __dirname + typeof __filename);
GLOBAL.IN_BROWSER = !GLOBAL.IN_EL && !GLOBAL.global && "document" in GLOBAL;
GLOBAL.IN_WORKER = !GLOBAL.IN_EL && !GLOBAL.global && "WorkerLocation" in GLOBAL;
GLOBAL.IN_NODE = !GLOBAL.IN_EL && !!GLOBAL.global && !/native/.test(setTimeout);
GLOBAL.IN_NW = !GLOBAL.IN_EL && !!GLOBAL.global && /native/.test(setTimeout);