UNPKG

496 BJavaScriptView Raw
1'use strict'
2
3module.exports = clone
4
5var getPrototypeOf = Object.getPrototypeOf || function (obj) {
6 return obj.__proto__
7}
8
9function clone (obj) {
10 if (obj === null || typeof obj !== 'object')
11 return obj
12
13 if (obj instanceof Object)
14 var copy = { __proto__: getPrototypeOf(obj) }
15 else
16 var copy = Object.create(null)
17
18 Object.getOwnPropertyNames(obj).forEach(function (key) {
19 Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(obj, key))
20 })
21
22 return copy
23}