(info) This AI is still in early stages of development.

object.addConst()

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

 

Syntax

obj.addConst(key, value);

Parameters

ParameterTypeMandatoryDescriptionUtil.js version
keyString(tick)

The name (key) of the property.

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

Return value

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

Adding a property to an object...
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)
}
Availability STABLE

Requires:

Contents

Jump to:

Property Definitions

Topics:

  • object.addAccessor() — Add a hidden, non-configurable accessor property to any object...
  • object.addProp() — Adds a new accessor (getter/setter) or data (value) property to any object, setting it's enumerable, configurable and read-only flags as desired...
  • object.addConst() — Add a hidden, read-only data property to any object...

Â