aswi2020vldc-gitlab/templetes/node_modules/graceful-fs/clone.js @ 9b6ff40e
1 |
'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 |
}
|