util

property
 owl.util 

owl.util

owl.util = {

clone

method
 clone() 

Option name Type Description
object object
isRecursive boolean
return object

Clones an object

clone: function(object, isRecursive) {
    var that = this,
        copy;

    if (null === object || typeof object !== 'object') {
        return object;
    }

    if (object instanceof Date) {
        copy = new Date();
        copy.setTime(object.getTime());
        return copy;
    }

    if (object instanceof Array) {
        copy = [];
        object.forEach(function(element, index) {
            copy[index] = that.clone(element);
        });
        return copy;
    }

    copy = {};
    Object.keys(object).forEach(function(key) {
        copy[key] = isRecursive ? that.clone(object[key], isRecursive) : object[key];
    });
    return copy;
},

extend

method
 extend() 

Option name Type Description
firstObject object
secondObject object
isRecursive boolean
return object

Extends and object

extend: function(firstObject, secondObject, isRecursive) {
    var that = this,
        result = this.clone(firstObject, true);

    Object.keys(secondObject).forEach(function(key) {
        if (typeof result[key] === 'object' && result[key] !== null && isRecursive) {
            result[key] = that.extend(result[key], secondObject[key], isRecursive);
        } else {
            result[key] = secondObject[key];
        }
    });

    return result;
}
    };
}(window, owl));