Versions Compared

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
themeRDark
languagejavascript
linenumberstrue
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

vVal
ParameterTypeMandatoryDescriptionUtil.js version
sNamenameString(tick)

The name of the global constant reference

0.8

property.

1.0
valueVariant(tick)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
themeRDark
languagejavascript
titleSame as using 'const' declaration in global scopeAdding a property to an object...
linenumberstrue
globalConstmyObj = {};
 
myObj.addConst("foo", "bar");
 
myObj.foo; // same as:
const foo = "bar";
Code Block
themeRDark
languagejavascript
titleCreate global constant from within a function
linenumberstrue
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
classbox
Availability

This feature requires:

  • Util.js v0.8 and above
Status
colourGreen
titleStable

Requires:

Div
classbox
Contents

Jump to:

Table of Contents
maxLevel5

Div
classbox

See also

Related articles:

global – reference to the global object/scope

Property Definitions

Topics:

Child pages (Children Display)
alltrue
depthall
pageProperty Definitions
excerpttrue