object

object

Source:
the JS native Object class

Methods

clone(o) → {object}

Source:
deeply clones an object in a new object

Example

eg. usage

var o = {
  prop1: 1,
  prop2: 'a',
};

var p = o.clone();

console.log(o == p); // true

console.log(o === p); // false
Parameters:
Name Type Description
o object the object
Returns:
Type
object

each(o, iteratee) → {object}

Source:
executes function for every property in the object

Example

eg. usage

var o = {
  prop1: 1,
  prop2: 'a',
  prop3: 'b',
  prop4: new Date(),
};

o.each(function(value, key) {
  console.log(key, value);
});

// it logs
'prop1', 1
'prop2', 'a'
'prop3', 'b'
'prop4', Date
Parameters:
Name Type Description
o object the object
iteratee function the iteratee callback will be invoked with the following parameters
so your callback has to be something like this

function iteratee(value, key) {}
Properties
Name Type Description
value any the property value of the object
key string the property key of the object
Returns:
to make chainable the method
Type
object

inherit(o, createNewopt, …args) → {object}

Source:
deep merges a variable list of objects inside this object instance or a new object (useful to implements defaults/options/settings pattern or set multiple properties at the same time or what you want)

Examples

eg. usage

var o = {
  prop1: 1,
  prop2: 'a',
};

o.inherit({
  prop1: 2,
  prop3: new Date(),
}, {
  prop4: 7.52,
});

console.log(o); // o = {prop1: 2, prop2: 'a', prop3: Date, prop4: 7.52}

or

var o = {
  prop1: 1,
  prop2: 'a',
};

var p = o.inherit(true, {
  prop1: 2,
  prop3: new Date(),
}, {
  prop4: 7.52,
});

console.log(o); // o = {prop1: 1, prop2: 'a'}

console.log(p); // p = {prop1: 2, prop2: 'a', prop3: Date, prop4: 7.52}
Parameters:
Name Type Attributes Description
o object the object to extend
createNew boolean <optional>
specifies to create a new object to merge
args object <repeatable>
the list of objects to merge
Returns:
Type
object

isObject(o) → {boolean}

Source:
isObject

Example

eg. usage

var o = {
  prop1: 1,
  prop2: 'a',
};

console.log(Object.isObject(o)); // true

console.log(Object.isObject(2)); // true

console.log(Object.isObject('2')); // true

console.log(Object.isObject(null)); // false
Parameters:
Name Type Description
o object the object
Returns:
Type
boolean

omit(o, …args) → {object}

Source:
returns a new object that omits the specified properties

Example

eg. usage

var o = {
  prop1: 1,
  prop2: 'a',
};

o.inherit({
  prop1: 2,
  prop3: new Date(),
}, {
  prop4: 7.52,
});

console.log(o); // o = {prop1: 2, prop2: 'a', prop3: Date, prop4: 7.52}

console.log(o.omit('prop1')); // {prop2: 'a', prop3: Date, prop4: 7.52}

console.log(o.omit('prop1', 'prop2')); // {prop3: Date, prop4: 7.52}

console.log(o.omit(['prop1', 'prop2'])); // {prop3: Date, prop4: 7.52}

console.log(o.omit(['prop1'], ['prop2'])); // {prop3: Date, prop4: 7.52}

console.log(o); // o = {prop1: 2, prop2: 'a', prop3: Date, prop4: 7.52}
Parameters:
Name Type Attributes Description
o object the object
args object <repeatable>
the list of properties to omit
Returns:
Type
object

path(o, path, defopt) → {*}

Source:
returns the value at the specified path of the object, with a default value

Examples

eg. usage

var o = {
  prop1: 1,
  prop2: 'a',
  prop3: {
    prop31: 2.52,
    prop32: 'b',
  },
  prop4: new Date(),
};

console.log(o.path('prop1')); // 1

console.log(o.path('prop3.prop31')); // 2.52

console.log(o.path('prop3.prop34')); // null

console.log(o.path('prop3.prop34', 'c')); // c

you can also use array paths

var o = {
  prop1: 1,
  prop2: 'a',
  prop3: {
    prop31: 2.52,
    prop32: [{
      propO1: 'b',
    }, {
      propO1: 'c',
    }],
  },
  prop4: new Date(),
};

console.log(o.path('prop3.prop32[0].propO1')); // 'b'

console.log(o.path('prop3.prop32[1]')); // {propO1: 'c'}

console.log(o.path('prop3.prop31[2]')); // null

console.log(o.path('prop3.prop31[2]', {})); // {}
Parameters:
Name Type Attributes Default Description
o object the object
path string the path to search inside the object
def object <optional>
null the default value to return if path is not found
Returns:
Type
*

pick(o, …args) → {*}

Source:
returns a new object that picks only the specified properties

Example

eg. usage

var o = {
  prop1: 1,
  prop2: 'a',
};

o.inherit({
  prop1: 2,
  prop3: new Date(),
}, {
  prop4: 7.52,
});

console.log(o); // o = {prop1: 2, prop2: 'a', prop3: Date, prop4: 7.52}

console.log(o.pick('prop1')); // {prop1: 2}

console.log(o.pick('prop1', 'prop2')); // {prop1: 2, prop2: 'a'}

console.log(o.pick(['prop1', 'prop2'])); // {prop1: 2, prop2: 'a'}

console.log(o.pick(['prop1'], ['prop2'])); // {prop1: 2, prop2: 'a'}

console.log(o); // o = {prop1: 2, prop2: 'a', prop3: Date, prop4: 7.52}
Parameters:
Name Type Attributes Description
o object the object
args object <repeatable>
the list of properties to omit
Returns:
Type
*