cwal

whcl: Object
Login

whcl: Object

(⬑Table of Contents) (data types)

Objects (a.k.a. Dictionaries, Hash tables, and Associative Arrays)

See also: the object builtin command

Jump to...

Objects

Object's are the framework's general-purpose container type, capable of holding arbitrary key-value pairs in unordered storage with amortized O(1) lookup speed. The Object class is the base class of almost every other class in the framework.

Object Methods

The methods provided by this class are inherited by most other classes in the library. They are listed in alphabetical order below.

clear-properties

Usage: clear-properties

Clears all properties from this object (not including prototypes) and returns this object.

copy-properties-to

Usage: copy-properties-to target [...targetN]

Copies all properties from this object to one or more target containers and returns the last target argument.

get

Usage: get key

Works just like $obj[key], returning the value for the given key or the undefined value. If passed an integer key and "this" is an array, it operates on an array index instead of a property key.

has-own-propery

Usage: has-own-propery key

Returns true if this object has its own copy of the given property, not considering any copies which a prototype might have.

is-empty

Usage: is-empty

Returns true if this object has no properties.

property-keys

Usage: property-keys

Returns an array of all property keys, or an empty array if the object has no properties.

set

Usage: set

Works just like set $obj[key] value.

property-count

Usage: property-count

Returns the number of properties in this object.

to-json

Usage: to-json [integer indentAmount [bool cyclesAsStrings=false]]

Returns a JSON-format string representation of this object. The first argument may be an integer or string. A positive integer is a number of spaces to indent per level, negative is a number of hard tabs.

With throw if the object contains any cycles unless passed a truthy second argument, in which case cycles are rendered in some unspecified debug-like form.

Non-JSON-able keys and values are elided.

to-string

Usage: to-string

Works just like to-json but does not accept any formatting options.

unset

Usage: unset key [...keyN]

Works just like unset $obj[key] but returns this object.

with-this

Usage: with-this aFunction

Calls the given function with this object as its this. Returns the result of that function unless the function returns undefined or does not explicitly return, in which case it returns this.