Repositorio del curso CCOM4030 el semestre B91 del proyecto kilometro0

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. }