How can I pass object passed into function without changing even if the passed object is has changed.
let theObj = {
parameter: '11'
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function myFunc(myObj) {
await sleep(5000)
console.log(myObj.parameter)
}
myFunc(theObj)
theObj.parameter = '22'
output:
> 22
How can I get 11 as the output, the value of theObj.parameter
when the function was called ?
I don't want to deep clone because of speed.