Last change
on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
496 bytes
|
Line | |
---|
1 | 'use strict'
|
---|
2 |
|
---|
3 | module.exports = clone
|
---|
4 |
|
---|
5 | var getPrototypeOf = Object.getPrototypeOf || function (obj) {
|
---|
6 | return obj.__proto__
|
---|
7 | }
|
---|
8 |
|
---|
9 | function 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 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.