Code coverage report for object/deepMixIn.js

Statements: 100% (15 / 15)      Branches: 85.71% (6 / 7)      Functions: 100% (4 / 4)      Lines: 100% (15 / 15)     

All files » object/ » deepMixIn.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 391 1             1 13       13 15 15 15       13     1 19       19 4   15       1      
// use collection/forEach since we also deep merge arrays during the process
define(['../collection/forEach'], function (forEach) {
 
    /**
     * Mixes objects into the target object, recursively mixing existing child
     * objects and arrays.
     * @version 0.1.1 (2012/11/08)
     */
    function deepMixIn(target, objects) {
        var i = 0,
            n = arguments.length,
            obj;
 
        while(++i < n){
            obj = arguments[i];
            Eif (obj) {
                forEach(obj, copyProp, target);
            }
        }
 
        return target;
    }
 
    function copyProp(val, key) {
        var existing = this[key];
        // WTFJS: `typeof null === 'object'` so we check if val is truthy.
        // need to use `typeof` check instead of lang/isObject since we also
        // need to deep merge arrays
        if (val && typeof val === 'object' && typeof existing === 'object') {
            deepMixIn(existing, val);
        } else {
            this[key] = val;
        }
    }
 
    return deepMixIn;
 
});