Skip to content

Object Functions

Rohansi edited this page Dec 22, 2014 · 11 revisions

object values have the following functions defined.

Note: Unless otherwise stated, the functions that return object just return the value they acted on, not a new value. This enables calls to be chained like this: {}.add('a', 1).add('b', 2)

add

add(key, value): object

Adds or overwrites a key-value pair in the object.

clear

clear(): object

Removes all values from the object, including any user-defined prototype value.

containsKey

containsKey(key): bool

Returns true if the object contains the given key.

containsValue

containsValue(value): bool

Returns true if the object contains the given value.

get

get(key): any

Returns the value for the given key, or undefined if it was not found.

remove

remove(key): object

Removes a key from the object.

length

length(): number

Returns the number of key-value pairs defined in the object. This does not include values inherited from the prototype.

getEnumerator

getEnumerator(): object

Returns an enumerator for iterating over values defined in the object. Values will be returned as key-value pair objects: { key: 'age', value: 12 }

setPrototype

setPrototype(value: any): object

Sets the object's prototype. value should be an object, null, or undefined. null will remove the prototype while undefined will restore the default prototype.

lock

lock(): object

Locks the object, preventing further modifications to it.

setPrototypeAndLock

setPrototypeAndLock(value: any): object

Set's the object's prototype and locks the object.