obj.js

Methods

(static) defineLazyProperty(obj, key, getValue, setter)

Object.defineProperty but "lazy", which means that the value is only set after it is retrieved the first time, rather than being set right away.

Parameters:
NameTypeDescription
objObject

the object to set the property on

keystring

the key for the property to set

getValuefunction

the function used to get the value when it is needed.

setterboolean

whether a setter should be allowed or not

(static) each(object, fn)

Array-like iteration for objects.

Parameters:
NameTypeDescription
objectObject

The object to iterate over

fnobj:EachCallback

The callback function which is called for each key in the object.

(static) isObject(value) → {boolean}

Returns whether a value is an object of any kind - including DOM nodes, arrays, regular expressions, etc. Not functions, though.

This avoids the gotcha where using typeof on a null value results in 'object'.

Parameters:
NameTypeDescription
valueObject
Returns:
Type: 
boolean

(static) isPlain(value) → {boolean}

Returns whether an object appears to be a "plain" object - that is, a direct instance of Object.

Parameters:
NameTypeDescription
valueObject
Returns:
Type: 
boolean

(static) merge(sources) → {Object}

Merge two objects recursively.

Performs a deep merge like lodash.merge, but only merges plain objects (not arrays, elements, or anything else).

Non-plain object values will be copied directly from the right-most argument.

Parameters:
NameTypeDescription
sourcesArray.<Object>

One or more objects to merge into a new object.

Returns:

A new object that is the merged result of all sources.

Type: 
Object

(static) reduce(object, fn, initialopt) → {*}

Array-like reduce for objects.

Parameters:
NameTypeAttributesDefaultDescription
objectObject

The Object that you want to reduce.

fnfunction

A callback function which is called for each key in the object. It receives the accumulated value and the per-iteration value and key as arguments.

initial*<optional>
0

Starting value

Returns:

The final accumulated value.

Type: 
*

(static) values(source) → {Array.<unknown>}

Returns an array of values for a given object

Parameters:
NameTypeDescription
sourceObject

target object

Returns:
  • object values
Type: 
Array.<unknown>

Type Definitions

obj:EachCallback(value, key)

Parameters:
NameTypeDescription
value*

The current key for the object that is being iterated over.

keystring

The current key-value for object that is being iterated over

obj:ReduceCallback(accum, value, key) → {*}

Parameters:
NameTypeDescription
accum*

The value that is accumulating over the reduce loop.

value*

The current key for the object that is being iterated over.

keystring

The current key-value for object that is being iterated over

Returns:

The new accumulated value.

Type: 
*