Versions Compared
compared with
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Excerpt |
---|
Define Add a global read-only, hidden data property to any object... |
Syntax
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
try { globalConst(sNameobj.addConst(name, vVal); } catch(e) { // likely a TypeError if an existing non-configurable property of the same sKey is defined }value); |
Parameters
Parameter | Type | Mandatory | Description | Util.js version | ||
---|---|---|---|---|---|---|
sNamename | String | The name of the global constant reference | 0.8 | vValproperty. | 1.0 | |
value | Variant | The value associated with the constant referenceproperty. | 1.0.8 |
Return value
If a non-configurable property of the same name is already defined, an error will likely be thrown.
Example
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
globalConstmyObj = {}; myObj.addConst("foo", "bar"); myObj.foo; // same as: const foo = "bar"; | ||||||||
Code Block | ||||||||
| ||||||||
function wibble() { const myObj.foo = "barmoo"; // error;does innothing, futurefoo mightis createread-only const within scope of wibble() globalConst("foo", "bar"); // creates global "foo" constant with value "bar" myObj.foo // "bar" for (i in myObj) { // does not iterate foo (foo is hidden) } |
Div | ||||||
---|---|---|---|---|---|---|
| ||||||
AvailabilityThis feature requires:
Requires:
|
Div | ||||
---|---|---|---|---|
| ||||
ContentsJump to:
|
Div | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
See alsoRelated articles: global – reference to the global object/scopeProperty DefinitionsTopics:
|