Projekt

Obecné

Profil

Stáhnout (401 Bajtů) Statistiky
| Větev: | Revize:
1 3a515b92 cagy
'use strict'
2
3
module.exports = clone
4
5
function clone (obj) {
6
  if (obj === null || typeof obj !== 'object')
7
    return obj
8
9
  if (obj instanceof Object)
10
    var copy = { __proto__: obj.__proto__ }
11
  else
12
    var copy = Object.create(null)
13
14
  Object.getOwnPropertyNames(obj).forEach(function (key) {
15
    Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(obj, key))
16
  })
17
18
  return copy
19
}