您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

clone.js 401B

12345678910111213141516171819
  1. 'use strict'
  2. module.exports = clone
  3. function clone (obj) {
  4. if (obj === null || typeof obj !== 'object')
  5. return obj
  6. if (obj instanceof Object)
  7. var copy = { __proto__: obj.__proto__ }
  8. else
  9. var copy = Object.create(null)
  10. Object.getOwnPropertyNames(obj).forEach(function (key) {
  11. Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(obj, key))
  12. })
  13. return copy
  14. }