合并对象的可枚举的属性

合并对象的可枚举的属性/方法到指定对象。

合并对象的可枚举的属性/方法到指定对象。

// typeOf, return: 'array', 'object', 'function', 'null', 'undefined', 'string', 'number'

const typeOf = exports.typeOf = input => {
  return ({}).toString.call(input).slice(8, -1).toLowerCase()
}

// merge object properties
const merge = exports.merge = (obj, options) => {
  if (obj && options) {
  for (let p in options) {
    if (options.hasOwnProperty(p)) {
    if (typeOf(options[p]) === 'object') {
      merge(obj[p], options[p])
    } else {
      obj[p] = options[p]
    }
    }
  }
  }
  return obj
}

 

Was this helpful?

0 / 0

发表评论 0

Your email address will not be published. Required fields are marked *