[Feature Request] Built-in `deepCopy/deepClone` (based on the structured cloning algorithm)
# Jordan Harband (6 years ago)
You may be interested to read some previous discussions around this topic:
You may be interested to read some previous discussions around this topic: - https://esdiscuss.org/topic/structured-clones - https://esdiscuss.org/topic/the-structured-clone-wars - https://esdiscuss.org/topic/object-clone-not-quite-a-proposal - https://esdiscuss.org/topic/object-equals-and-object-clone On Fri, Dec 7, 2018 at 6:00 AM Harry Manchanda <harmanmanchanda182 at gmail.com> wrote: > Heya, I tried before to write this but seems like I wasn't subscribed. Now > seems like I subscribed so posting it again... > > So here we go, > > I am posting this after an aftermath of a Github Issue. See => > https://github.com/tc39/proposals/issues/150 > > I would like the JavaScript (ECMAScript) Spec to include built-in > `deepCopy/deepClone` feature. > > Please note that based on the response at Github Issue and also > considering that the top 3 npm packages for cloning have over 100k weekly > downloads I am very positive on this and should be really considered. > > I think we have two approaches to consider for same > > 1. Object Oriented approach > > ```js > // Object.prototype.deepCopy(), Array.prototype.deepCopy(), etc > > const harry = { > name: 'Harry Manchanda', > age: 25, > social: [ > { > website: 'twitter', > username: '@harmanmanchanda', > }, > { > website: 'facebook', > username: 'IamManchanda', > }, > ], > }; > > const dev = harry.deepCopy(); > dev.social[1].website = 'github'; > ``` > > 2. Functional Programming approach > > ```js > // Object.deepCopy(value) > // Value expects array, objects and primitives > > const harry = { > name: 'Harry Manchanda', > age: 25, > social: [ > { > website: 'twitter', > username: '@harmanmanchanda', > }, > { > website: 'facebook', > username: 'IamManchanda', > }, > ], > }; > > const dev = Object.deepCopy(harry); > dev.social[1].website = 'github'; > ``` > > > Reason why I think so strongly that everyone in javascript community needs > this is this > > => https://gist.github.com/search?l=JavaScript&q=deepcopy > => https://gist.github.com/search?l=JavaScript&q=deepclone > => https://github.com/search?l=JavaScript&q=deepcopy&type=Repositories > => https://github.com/search?l=JavaScript&q=deepclone&type=Repositories > > > *Thanks,* > > *Harman Singh Manchanda ( Harry )* > *Open Source Team Member - Zurb Foundation > <https://foundation.zurb.com/get-involved/yetinauts.html>* > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20181207/2bc6f089/attachment-0001.html>
Heya, I tried before to write this but seems like I wasn't subscribed. Now seems like I subscribed so posting it again...
So here we go,
I am posting this after an aftermath of a Github Issue. See =>
tc39/proposals#150
I would like the JavaScript (ECMAScript) Spec to include built-in
deepCopy/deepClone
feature.Codepen Example Link: codepen.io/IamManchanda/pen/XYpVPY?editors=0012
Please note that based on the response at Github Issue and also considering that the top 3 npm packages for cloning have over 100k weekly downloads I am very positive on this and should be really considered.
I think we have two approaches to consider for same
// Object.prototype.deepCopy(), Array.prototype.deepCopy(), etc const harry = { name: 'Harry Manchanda', age: 25, social: [ { website: 'twitter', username: '@harmanmanchanda', }, { website: 'facebook', username: 'IamManchanda', }, ], }; const dev = harry.deepCopy(); dev.social[1].website = 'github';
// Object.deepCopy(value) // Value expects array, objects and primitives const harry = { name: 'Harry Manchanda', age: 25, social: [ { website: 'twitter', username: '@harmanmanchanda', }, { website: 'facebook', username: 'IamManchanda', }, ], }; const dev = Object.deepCopy(harry); dev.social[1].website = 'github';
Reason why I think so strongly that everyone in javascript community needs this is this
=> gist.github.com/search?l=JavaScript&q=deepcopy => gist.github.com/search?l=JavaScript&q=deepclone => search?l=JavaScript&q=deepcopy&type=Repositories => search?l=JavaScript&q=deepclone&type=Repositories
Thanks,
Harman Singh Manchanda ( Harry ) Open Source Team Member - Zurb Foundation foundation.zurb.com/get-involved/yetinauts.html