$jsapi.context
This method returns an object which represents the current request context.
tip
This is the same object as the one contained by the
$context built-in JavaScript variable.How to use
You cannot access the built-in variables directly:
- in JS actions;
- in JS files if the functions will be executed in the ECMAScript 5 runtime.
In these cases, access the variables via $jsapi.context:
- To access
$context, use$jsapi.context(). - To access any other built-in variable, use
$jsapi.context().<name>, where<name>is the variable name without the$prefix.
Examples:
-
You can access
$sessionvia$jsapi.context().session. For convenience, you can create a reference to this object using a local variable with the same name:var $session = $jsapi.context().session; -
You can access
$clientvia$jsapi.context().client:function getName() {
return $jsapi.context().client.name;
}
function setName(newName) {
var $client = $jsapi.context().client;
$client.name = newName;
}