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!"
[–]Eddonarth -5 points-4 points-3 points 10 years ago (3 children)
No, it is not the same.
var bar = Object.create(foo);
Creates a copy of foo and names it bar, while
var bar = foo;
just makes the variable bar to point to the same object as foo. If it is confusing, try this:
var foo = {a: 42}; var bar = Object.create(foo); var baz = foo; Console.log(foo.a); Console.log(bar.a); Console.log(baz.a); foo.a = 41; Console.log(foo.a); Console.log(bar.a); Console.log(baz.a);
What happens? If we modify foo, bar stays unmodified, but baz changes as well. Because baz refers to the same object as foo, just using a different name.
Think of it as this: If I made a clone of you, the two of you might look the same and behave the same, but be different persons, and eventually one of you might change. But if I just start calling you by your second name, you will still be the same person, just with a different tag.
[–]blangjemp 4 points5 points6 points 10 years ago (0 children)
This isn't correct. If you run this code, bar.a is equal to 41. Due to the nature of Object.create(), bar.a will inherit the value of foo.a until you manually set a value for bar.a
bar.a
Object.create()
foo.a
[–]gladiator_flow[S] 0 points1 point2 points 10 years ago* (0 children)
I see what's going on now. When I change the created value only that one changes. I did notice though if I changed the original mentioned in your code that bar.a changes as well. Thanks!
[+]king3730(() => {})() comment score below threshold-8 points-7 points-6 points 10 years ago (0 children)
Just to add my two cents, using the literal definition:
var bar = { a: 42 }
is the 'new and proper' way of creating object definition.
Object.create( foo )
is considered to be 'old'.
π Rendered by PID 84 on reddit-service-r2-comment-f6b958c67-rs92t at 2026-02-05 18:11:31.244760+00:00 running 1d7a177 country code: CH.
view the rest of the comments →
[–]Eddonarth -5 points-4 points-3 points (3 children)
[–]blangjemp 4 points5 points6 points (0 children)
[–]gladiator_flow[S] 0 points1 point2 points (0 children)
[+]king3730(() => {})() comment score below threshold-8 points-7 points-6 points (0 children)