API Docs for: 0.1.0
Show:

mclib.object Class

Class or Namespace containing object related functions

Methods

compare

(
  • objA
  • objB
)

Performs a shallow compare of two objects to determine their equality.

Parameters:

  • objA Object

    An object to be compared.

  • objB Object

    An object to be compared.

Example:

var obj1 = {a:1, b:2, c:3},

if (mclib.object.compare(obj1, {a:1, b:2, c:3})) {
    // they're equal. 
}

compareList

(
  • listA
  • listB
)

Performs a shallow compare of two arrays to determine their equality.

Parameters:

  • listA Array

    A list to be compared.

  • listB Array

    A list to be compared.

Example:

var list1 = [1, 2, 3],

if (mclib.object.compareList(list1, [1, 2, 3])) {
    // they're equal. 
}

filterClass

(
  • obj
  • condition
)

Performs a condition function against each member of an object and return an object of matches.

Parameters:

  • obj Object

    An object to traverse.

  • condition Object

    A function to perform against each (value, member).

Example:

var obj1 = {a:1, b:2, c:3},

var x = mclib.object.filterClass(obj1, function(value, member) {
        if (value === 1 || member === "b") {
            return true;
        }
        else {
            return false;
        }
})

x will equal {a:1,b:2}

forArray

(
  • list
  • procedure
)

Run a procedure for every item in an array.

Parameters:

  • list Array

    The array to traverse

  • procedure Function

    Function to run for each item passing (value, index)

Example:

var array1 = [1, 2, 3],
    array2 = [],
    array3 = mclib.object.forArray(list1, function (value, index) {
        array2.push(value);
    });

Results: array2 = [1, 2, 3]

forceMerge

(
  • objdest
  • objsrc
)

Merge an object into an existing object overwriting existing properties and methods in the original object.

Parameters:

  • objdest Object

    The destination object for the merge. If null, undefined or empty this operation will be treated as a shallow clone.

  • objsrc Object

    The source object for the merge. If null or undefined this operation will copy this object namespace into the destination object.

Example:

var obj1 = {a:1, b:2, merge:10},
    obj2 = {b:3, c:4},
    obj3 = mclib.object.merge(obj1, obj2);

Results: obj1 = {a:1,b:3,c:4,merge:10), obj2 = {b:3, c:4}, obj3 = {a:1,b:3,c:4,merge:10}

    mclib.object.merge(obj1);

Results: obj1 = {a:1,b:3,c:4,merge:function...,forceMerge:function...,...}

    obj3 = mclib.object.merge({},obj2);

Results: obj3 = {b:3,c:4}

forEach

(
  • obj
  • procedure
)

Run a procedure for every member in an object.

Parameters:

  • obj Object

    The object to traverse

  • procedure Function

    Function to run for each member passing (value, member)

Example:

var obj1 = {a:1, b:2, c: function(a) { var b = a;}},
    obj2 = {},
    obj3 = mclib.object.forEach(obj1, function (value, member) {
        obj2[member] = value;
    });

Results: obj2 = {a:1, b:2, c: function(a) { var b = a;}}

forEachWithoutFunctions

(
  • obj
  • procedure
)

Run a procedure for every member in an object. Don't invoke for functions.

Parameters:

  • obj Object

    The object to traverse

  • procedure Function

    Function to run for each member passing (value, member)

Example:

var obj1 = {a:1, b:2, c: function(a) { var b = a;}},
    obj2 = {},
    obj3 = mclib.object.forEachWithoutFunctions(obj1, function (value, member) {
        obj2[member] = value;
    });

Results: obj2 = {a:1, b:2}

getMemberList

(
  • obj
)

Returns an array of the name of members in an item.

Parameters:

  • obj Object

    The object whose memberss interest you.

Example:

var obj1 = {a:1, b:2, c:3, merge: function...},
    list = mclib.object.getMemberList(obj1);

Results: list = ["a","b","c","merge"]

getMemberListWithoutFunctions

(
  • obj
)

Returns an array of the name of properties from an object.

Parameters:

  • obj Object

    The object whose properties interest you.

Example:

var obj1 = {a:1, b:2, c:3, merge: function...},
    list = mclib.object.getMemberListWithoutFunctions(obj1);

Results: list = ["a","b","c"]

getMemberValueListWithoutFunctions

(
  • obj
)

Returns an array of the membernames/values from an object.

Parameters:

  • obj Object

    The object whose properties interest you.

Example:

var obj1 = {a:1, b:2, c:3, merge: function...},
    list = mclib.object.getMemberValueListWithoutFunctions(obj1);

Results: list = [["a",1],["b",2],["c",3]]

getValueListWithoutFunctions

(
  • obj
)

Returns an array of the values from an object.

Parameters:

  • obj Object

    The object whose properties interest you.

Example:

var obj1 = {a:1, b:2, c:3, merge: function...},
    list = mclib.object.getValueListWithoutFunctions(obj1);

Results: list = [1,2,3]

matchingFromList

(
  • list
  • condition
)

Performs a condition function against each item in a list and return an array of matches.

Parameters:

  • list Object

    A list to traverse.

  • condition Object

    A function to perform against each (value, index).

Example:

var list1 = [1,2,3],

var x = mclib.object.matchingFromList(list1, function(value, index) {
        if (value === 1 || index === 2) {
            return true;
        }
        else {
            return false;
        }
})

x will equal [1,2]

merge

(
  • objdest
  • objsrc
)

Merge an object into an existing object without overwriting anything in the original object.

Parameters:

  • objdest Object

    The destination object for the merge. If null, undefined or empty this operation will be treated as a shallow clone.

  • objsrc Object

    The source object for the merge. If null or undefined this operation will copy this object namespace into the destination object.

Example:

var obj1 = {a:1, b:2},
    obj2 = {b:3, c:4},
    obj3 = mclib.object.merge(obj1, obj2);

Results: obj1 = {a:1,b:2,c:4), obj2 = {b:3, c:4}, obj3 = {a:1,b:2,c:4}

    mclib.object.merge(obj1);

Results: obj1 = {a:1,b:2,c:4,merge:function...,forceMerge:function...,...}

    obj3 = mclib.object.merge({},obj2);

Results: obj3 = {b:3,c:4}