Object.assign

9 天前(已编辑)

Object.assign

Object.assign

function assign(target: object, ...sources: any[]): object {
  if (!isObject(target)) {
    throw new TypeError('The target must be an Object not a function')
  }
  sources.forEach(source => {
    let descriptors = Object.keys(source).reduce((descriptor, key) => {
      descriptor[key] = Object.getOwnPropertyDescriptor(source, key)
      return descriptor
    }, {})
    // assign enumerable Symbols
    Object.getOwnPropertySymbols(source).forEach(sym => {
      let descriptor = Object.getOwnPropertyDescriptor(source, sym)
      if (descriptor?.enumerable) {
        descriptors[sym] = descriptor
      }
    })
    // assign descriptors to target
    Object.defineProperties(target, descriptors)
  })
  
  return target
}

使用社交账号登录

  • Loading...
  • Loading...
  • Loading...
  • Loading...
  • Loading...