Versions Compared

Key

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

Add a hidden, read-only , hidden data property to any object...

 

Syntax

Code Block
themeRDark
languagejavascript
linenumberstrue
obj.addConst(namekey, value);

Parameters

ParameterTypeMandatoryDescriptionUtil.js version
namekeyString(tick)

The name (key) of the property.

1.0
valueVariant(tick)The value associated with the property.1.0

Return value

If a non-configurable property of the same name is already defined, an error will 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
titleAdding a property to an object...
linenumberstrue
myObj = {};
 
myObj.addConst("foo", "bar");
 
myObj.foo; // "bar"
 
myObj.foo = "moo"; // does nothing, foo is read-only
 
myObj.foo // "bar"
 
for (i in myObj) {
	// does not iterate foo (foo is hidden)
}
Div
classbox
Availability
Status
colourGreen
titleStable

Requires:

Div
classbox
Contents

Jump to:

Table of Contents
maxLevel5

Div
classbox

Property Definitions

Topics:

Child pages (Children Display)
alltrue
depthall
pageProperty Definitions
excerpttrue