Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
Excerpt

Define Add a global hidden, read-only , hidden propertydata property to any object...

 

Syntax

Code Block
themeRDark
languagejavascript
linenumberstrue
try {
  globalConst(sNameobj.addConst(key, vVal);
} catch(e) {
  // likely a TypeError if an existing non-configurable property of the same sKey is defined
}value);

Parameters

vVal
ParameterTypeMandatoryDescriptionUtil.js version
sNamekeyString(tick)

The name (key) 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.

ValueTypeNotesAPI Version
<object>ObjectIf successful, the addProp() method returns the modified object.1.0
<error>TypeError

An error will be thrown if:

  • The parameters are invalid, or
  • The object is not extensible, or
  • The key being modified is non-configurable.
1.0

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

See also

Related articles:

global – reference to the global object/scope
Contents

Jump to:

Table of Contents
maxLevel5

Div
classbox

Property Definitions

Topics:

Child pages (Children Display)
alltrue
depthall
pageProperty Definitions
excerpttrue