JSFiddle - React, Tailwind, and code Playground
by kassiomaia
JavaScript
class Value {
constructor(value) {
this.value = value
}
changeValue(newValue) {
this.value = newValue
}
}
const target = {
name: 'test',
children: [
'documents',
'projects',
'others',
new Value(10),
],
properties: {
development: true,
enviroment: {
variables: ['value', 'value', new Value(10)],
}
}
}
function deepClone(target) {
return Object.getOwnPropertyNames(target).reduce((obj, property) => {
const propertyDescriptor = Object.getOwnPropertyDescriptor(target, property)
obj[property] = propertyDescriptor.value
return obj
}, {})
}
console.log(deepClone(target))