can-globals
An environment agnostic container for global variables. Useful for testing and server-side rendering (SSR), typically used internally by CanJS.
Object
The can-globals
package exports an object with
methods used to set and get global variables. For example, get the global location
object:
import globals from "can-globals";
const LOCATION = globals.getKeyValue( "location" );
New keys can be defined with the define
method, overwritten with the setKeyValue
method, and reset to their original value with the reset
method.
All of these methods are demonstrated in the following example
import globals from "can-globals";
globals.define( "foo", "bar" ); // foo === 'bar'
globals.setKeyValue( "foo", "baz" ); // foo === 'baz'
globals.reset( "foo" ); // foo === 'bar'