Created
January 26, 2018 11:55
-
-
Save fodra/64ed84564d6f2a8d9d226711fd43c85d to your computer and use it in GitHub Desktop.
This is how you perform a deep copy in javascript as discussed in the HN article: Deep-copying in JavaScript.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function deepCopy(obj) { | |
| return new Promise(resolve => { | |
| const {send, recv} = new MessageChannel(); | |
| recv.onmessage = ev => resolve(ev.data); | |
| send.postMessage(obj); | |
| }); | |
| } | |
| const obj = /* object to copy */; | |
| const clone = await deepCopy(obj); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment