new DefaultMap( factory [, iterable ] )

Description

Subclass of Map that is similar to Python's defaultdict.

First argument is a factory function that will create a new default value for the key if not already present in the container.

The factory function may take arguments. When getWithArguments is used, those arguments will be passed to the factory.

Parameters
Name Type Attributes Description
factory function

Function that creates a new default value if a requested key is not present.

iterable Iterable <optional>

Passed to external:Map's super.

Details

Methods


get( key ) → {object}

Parameters
Name Type Description
key object

The key of the element to return from this instance.

Returns

The value associated with the key, perhaps newly created.

Details

getWithArguments( key, ...args ) → {object}

Description

Variant of external:Map#get that passes args to the factory.

Parameters
Name Type Attributes Description
key object

The key of the element to return from this instance.

args object <repeatable>

Extra arguments passed to the factory function if it is called.

Returns

The value associated with the key, perhaps newly created.

Details