Namespace Obj
Functions for dealing with Objects.
Defined in: nativelib-dev.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Method Attributes | Method Name and Description |
---|---|
<static> |
Obj.alias(o, map)
Maps each property to its value.
|
<static> |
Obj.copy(o)
Copies each property of the provided object into a new object,
creating a shallow copy.
|
<static> |
Obj.create(pairs)
Creates a new object from an array of property-value pairs.
|
<static> |
Obj.detect()
Alias of filterOne.
|
<static> |
Obj.each()
Alias of forEach.
|
<static> |
Obj.equals(o, o2)
Compares the value of each property in each object.
|
<static> |
Obj.filter(o, fn, ctx)
Creates a new object containing only the properties that return
true when passed to the provided function.
|
<static> |
Obj.filterOne(o, fn, ctx)
The same as filter, but only returning the first match.
|
<static> |
Obj.forEach(o, fn, ctx)
Runs the passed function for each property in the object.
|
<static> |
Obj.fromPath(path, root)
Returns an object matching the specified path, if it exists.
|
<static> |
Obj.invoke(o, name, args, ctx)
Calls the property, if present, on each property in the passed
object, returning an object with the results at each property.
|
<static> |
Obj.keys(o)
Creates an array containing the property names of an object.
|
<static> |
Obj.map(o, fn, ctx)
Creates an array containing the values of a function applied to
each property in the object.
|
<static> |
Obj.merge(o, props, clobber)
Adds all of the passed properties if they are not already
defined.
|
<static> |
Obj.namespace(path)
Creates a nested object to the depth specified, not overwriting
existing properties.
|
<static> |
Obj.ns()
Alias of namespace
|
<static> |
Obj.select()
Alias of filter.
|
<static> |
Obj.test(o)
Checks if the passed item is an object.
|
<static> |
Obj.values(o)
Returns each property's value.
|
<static> |
Obj.valuesEqual(a, b)
Checks if the two passed objects are equal, performing deep
checks for Objects and Arrays.
|
Method Detail
<static>
{Object}
Obj.alias(o, map)
Maps each property to its value.
var o = { a: 1 }; Object.alias(o, { a: 'b' }; // { a: 1, b: 1 } Object.alias(o, { b: ['c', 'd'] }; // { a: 1, b: 1, c: 1, d: 1 }
- Parameters:
- {Object} o
- The object to modify (in-place).
- {Object} map
- The properties to map.
- Returns:
- {Object} The modified object.
<static>
{Object}
Obj.copy(o)
Copies each property of the provided object into a new object,
creating a shallow copy.
- Parameters:
- {Object} o
- The object to copy.
- Returns:
- {Object} The copied object.
<static>
{Object}
Obj.create(pairs)
Creates a new object from an array of property-value pairs.
Object.create([['a', 1], ['b', 2]]); // { a: 1, b: 2 }
- Parameters:
- {Array} pairs
- The pair array.
- Returns:
- {Object} The created object.
<static>
Obj.detect()
Alias of filterOne.
<static>
Obj.each()
Alias of forEach.
<static>
{Boolean}
Obj.equals(o, o2)
Compares the value of each property in each object.
- Parameters:
- {Object} o
- One object to compare.
- {Object} o2
- The object to compare it with.
- Returns:
- {Boolean} true if the properties are equal, false if not.
<static>
{Object}
Obj.filter(o, fn, ctx)
Creates a new object containing only the properties that return
true when passed to the provided function.
- Parameters:
- {Object} o
- The object to filter.
- {Function} fn
- The filtering function.
- {Object} ctx
- The function's execution context.
- Returns:
- {Object} The filtered object.
<static>
Obj.filterOne(o, fn, ctx)
The same as filter, but only returning the first match.
- Parameters:
- {Object} o
- The object to filter.
- {Function} fn
- The filtering function.
- {Object} ctx
- The function's execution context.
- Returns:
- The first filtered item, if found.
<static>
Obj.forEach(o, fn, ctx)
Runs the passed function for each property in the object.
- Parameters:
- {Object} o
- The object to iterate.
- {Function} fn
- The function to call.
- {Object} ctx
- The function's execution context.
<static>
{Object}
Obj.fromPath(path, root)
Returns an object matching the specified path, if it exists.
- Parameters:
- {String} path
- The period '.' separated object path.
- {Object} root
- The root path (default is window).
- Returns:
- {Object} The object, if found.
<static>
{Object}
Obj.invoke(o, name, args, ctx)
Calls the property, if present, on each property in the passed
object, returning an object with the results at each property. If
the named property is not present on a given item, the result
property will be undefined.
- Parameters:
- {Object} o
- The object
- {String} name
- The property name to call.
- {Array} args
- An argument list that will be provided with each call.
- {Object} ctx
- The function's execution context.
- Returns:
- {Object} The return value of each call.
<static>
{Array}
Obj.keys(o)
Creates an array containing the property names of an object.
- Parameters:
- {Object} o
- The object
- Returns:
- {Array} The object's keys
<static>
{Object}
Obj.map(o, fn, ctx)
Creates an array containing the values of a function applied to
each property in the object.
Object.map({ Rice: 'Jerry', Clark: 'Gary' }, function (v, p, o) { return p + ', ' + v; }; // { Rice: 'Rice, Jerry', Clark: 'Clark, Gary' }
- Parameters:
- {Object} o
- The object to iterate.
- {Function} fn
- The map function.
- {Object} ctx
- The function's execution context, called with (value, property, object).
- Returns:
- {Object} The mapped object.
<static>
{Object}
Obj.merge(o, props, clobber)
Adds all of the passed properties if they are not already
defined.
var o = { a: 1 }; Object.merge(o, { a: 2, b: 2 }); o; // { a: 1, b: 2 }
- Parameters:
- {Object} o
- The object to modify (in-place).
- {Object} props
- The properties to write.
- {Boolean} clobber
- true to overwrite defined properties
- Returns:
- {Object} The modified object.
<static>
{Object}
Obj.namespace(path)
Creates a nested object to the depth specified, not overwriting
existing properties.
- Parameters:
- {String} path
- The period '.' separated object path.
- Returns:
- {Object} The resulting object.
<static>
Obj.ns()
Alias of namespace
<static>
Obj.select()
Alias of filter.
<static>
{Boolean}
Obj.test(o)
Checks if the passed item is an object.
- Parameters:
- {Object} o
- The item to check.
- Returns:
- {Boolean} true if it is an object, false if not.
<static>
{Array}
Obj.values(o)
Returns each property's value.
- Parameters:
- {Object} o
- The object to use.
- Returns:
- {Array} An array of values.
<static>
{Boolean}
Obj.valuesEqual(a, b)
Checks if the two passed objects are equal, performing deep
checks for Objects and Arrays.
- Parameters:
- {Object} a
- The item to check.
- {Object} b
- The item to check it against.
- Returns:
- {Boolean} true if the values are equal, false if not.