Module: Environment

Environment

Method Summary

browserDocumentOrDie
Helper method that will throw an IllegalStateException if the return value of isBrowserDocument is false.
isBrowser
Checks if the code is running inside a Browser.
isBrowserDocument
Checks if the code is running inside an HTML document.
isNodeJS
Checks if the code is running inside Node.
isWebWorker
Checks if the code is running inside a WebWorker.

Method Detail

<static> browserDocumentOrDie()

Helper method that will throw an IllegalStateException if the return value of isBrowserDocument is false. This method is supposedly called as first thing in a module definition.
Throws:
if this function is not called inside a HTML page. The message of the error is the following: "Trying to load a browser-only module on non-browser environment".
Type
IllegalStateException
Example
define(["Environment"],function(Environment) {
  Environment.browserDocumentOrDie();
  
  //module definition here
});

<static> isBrowser() → {Boolean}

Checks if the code is running inside a Browser. The code might be either running inside a HTML page or inside a WebWorker.
Note that browsers not supporting DOM Level 2 (i.e.: document.getElementById) are not recognized by this method
Returns:
true if the code is running inside a Browser, false otherwise.
Type
Boolean

<static> isBrowserDocument() → {Boolean}

Checks if the code is running inside an HTML document.
Note that browsers not supporting DOM Level 2 (i.e.: document.getElementById) are not recognized by this method
Returns:
true if the code is running inside a Browser document, false otherwise.
Type
Boolean

<static> isNodeJS() → {Boolean}

Checks if the code is running inside Node.js.
Returns:
true if the code is running inside Node.js, false otherwise.
Type
Boolean

<static> isWebWorker() → {Boolean}

Checks if the code is running inside a WebWorker.
Returns:
true if the code is running inside a WebWorker, false otherwise.
Type
Boolean