blob: 028356c96ed53635ba5291f16773ed556cb61983 [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001'use strict'
2
3module.exports = clone
4
5function 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}