Class: Wrapper

Wrapper

new Wrapper(object) → {Wrapper}

Wrap an object for one method call.

Note that the new keyword is not necessary.

Parameters:
Name Type Description
object object | null | undefined

null or undefined is treated as an empty plain object.

Returns:

The wrapped object.

Type
Wrapper

Members

(static) chain

Wrap an object for a chain of method calls.

Calls the constructor Wrapper() and modifies the wrapper for chaining.

Methods

each(iteratee, contextopt) → {Wrapper}

Mimics Underscore's each method: Iterate over the members of the wrapped object, calling iteratee() with each.

Parameters:
Name Type Attributes Description
iteratee function

For each member of the wrapped object, this function is called with three arguments: (value, key, object). The return value of this function is undefined; an .each loop cannot be broken out of (use .find instead).

context object <optional>

If given, iteratee is bound to this object. In other words, this object becomes the this value in the calls to iteratee. (Otherwise, the this value will be the unwrapped object.)

Returns:

The wrapped object for chaining.

Type
Wrapper

extend(source) → {Wrapper|object}

Mimics Underscore's extend method: Copy all of the properties in each of the source object parameter(s) over to the (wrapped) destination object (thus mutating it). It's in-order, so the properties of the last source object will override properties with the same name in previous arguments or in the destination object.

This method copies own members as well as members inherited from prototype chain.

Parameters:
Name Type Description
source object | null | undefined

Values of null or undefined are treated as empty plain objects.

Returns:

The wrapped destination object if chaining is in effect; otherwise the unwrapped destination object.

Type
Wrapper | object

extendOwn(source) → {Wrapper|object}

Mimics Underscore's extendOwn method: Like extend, but only copies its "own" properties over to the destination object.

Parameters:
Name Type Description
source object | null | undefined

Values of null or undefined are treated as empty plain objects.

Returns:

The wrapped destination object if chaining is in effect; otherwise the unwrapped destination object.

Type
Wrapper | object

filter(predicate, contextopt) → {*}

Mimics Underscore's filter method: Look through each member of the wrapped object, returning the values of all members that pass a truth test (predicate), or empty array if no value passes the test. The function always traverses the entire object.

Parameters:
Name Type Attributes Description
predicate function

For each member of the wrapped object, this function is called with three arguments: (value, key, object). The return value of this function should be truthy if the member passes the test and falsy otherwise.

context object <optional>

If given, predicate is bound to this object. In other words, this object becomes the this value in the calls to predicate. (Otherwise, the this value will be the unwrapped object.)

Returns:

An array containing the filtered values.

Type
*

find(predicate, contextopt) → {*}

Mimics Underscore's find method: Look through each member of the wrapped object, returning the first one that passes a truth test (predicate), or undefined if no value passes the test. The function returns the value of the first acceptable member, and doesn't necessarily traverse the entire object.

Parameters:
Name Type Attributes Description
predicate function

For each member of the wrapped object, this function is called with three arguments: (value, key, object). The return value of this function should be truthy if the member passes the test and falsy otherwise.

context object <optional>

If given, predicate is bound to this object. In other words, this object becomes the this value in the calls to predicate. (Otherwise, the this value will be the unwrapped object.)

Returns:

The found property's value, or undefined if not found.

Type
*

map(iteratee, contextopt) → {*}

Mimics Underscore's map method: Produces a new array of values by mapping each value in list through a transformation function (iteratee). The function always traverses the entire object.

Parameters:
Name Type Attributes Description
iteratee function

For each member of the wrapped object, this function is called with three arguments: (value, key, object). The return value of this function is concatenated to the end of the new array.

context object <optional>

If given, iteratee is bound to this object. In other words, this object becomes the this value in the calls to predicate. (Otherwise, the this value will be the unwrapped object.)

Returns:

An array containing the filtered values.

Type
*

reduce(iteratee, memoopt, contextopt) → {*}

Mimics Underscore's reduce method: Boil down the values of all the members of the wrapped object into a single value. memo is the initial state of the reduction, and each successive step of it should be returned by iteratee().

Parameters:
Name Type Attributes Description
iteratee function

For each member of the wrapped object, this function is called with four arguments: (memo, value, key, object). The return value of this function becomes the new value of memo for the next iteration.

memo * <optional>

If no memo is passed to the initial invocation of reduce, the iteratee is not invoked on the first element of the list. The first element is instead passed as the memo in the invocation of the iteratee on the next element in the list.

context object <optional>

If given, iteratee is bound to this object. In other words, this object becomes the this value in the calls to iteratee. (Otherwise, the this value will be the unwrapped object.)

Returns:

The value of memo "reduced" as per iteratee.

Type
*

value() → {object|null|undefined}

Unwrap an object wrapped with Wrapper.chain().

Returns:

The value originally wrapped by the constructor.

Type
object | null | undefined