All files / obj cover.js

100% Statements 12/12
90% Branches 9/10
100% Functions 3/3
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                          2x 2x 2x 1x 1x 1x 1x 2x 1x           1x     1x     1x  
/**
 * 覆盖对象,不添加新的键
 * @method obj/cover
 * @param {Object} object 要覆盖的对象
 * @param {Object} item 要覆盖的属性键值对
 * @returns {Object} 覆盖后的源对象
 * @example
 * var $cover = require('@spore-ui/kit/packages/obj/cover');
 * var obj = {a: 1, b: 2};
 * console.info($cover(obj,{b: 3, c: 4})); //{a: 1, b: 3}
 */
 
function cover() {
  var args = Array.prototype.slice.call(arguments);
  var object = args.shift();
  if (object && typeof object.hasOwnProperty === 'function') {
    var keys = Object.keys(object);
    args.forEach(function (item) {
      Eif (item && typeof item.hasOwnProperty === 'function') {
        keys.forEach(function (key) {
          if (item.hasOwnProperty(key)) {
            object[key] = item[key];
          }
        });
      }
    });
  } else {
    return object;
  }
 
  return object;
}
 
module.exports = cover;