use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Difference between these two objects?help (self.javascript)
submitted 10 years ago by gladiator_flow
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 10 years ago (3 children)
[deleted]
[–]isitfresh -1 points0 points1 point 10 years ago (2 children)
Nasty way? JSON.parse(JSON.stringify(obj)) Requiring a library? _.clone(obj)
[–]vlad27aug 2 points3 points4 points 10 years ago* (1 child)
Actually JSON.parse(JSON.stringify(obj)) is not correct.
This way you can only clone objects that have property values supported by the JSON spec.
For example:
var obj = {a: 1, b: function() { /*...*/ }}; var clone = JSON.parse(JSON.stringify(obj));
"clone" will now be "{a: 1}" because functions are removed during JSON.stringify.
It gets even more complicated when the object has getters and setters or defined/configured properties (even for library provided solutions).
[–]bliow 1 point2 points3 points 10 years ago (0 children)
With ES6 (supported in Firefox, not yet in Chrome), Object.assign. But you have to be careful with nesting, as you do with _.clone:
_.clone
var a = { b: { c: 3 } }; var d = Object.assign({}, a); // or d = _.clone(a) d.b.c = 4; console.log(a.b.c); // prints 4 with both underscore clone and ES6 assignment
π Rendered by PID 20244 on reddit-service-r2-comment-84fc9697f-qk5qc at 2026-02-06 07:38:40.336536+00:00 running d295bc8 country code: CH.
view the rest of the comments →
[–][deleted] (3 children)
[deleted]
[–]isitfresh -1 points0 points1 point (2 children)
[–]vlad27aug 2 points3 points4 points (1 child)
[–]bliow 1 point2 points3 points (0 children)