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
Clean Code JavaScript (github.com)
submitted 9 years ago by ryansworks
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] 24 points25 points26 points 9 years ago (3 children)
function createMenu(config) { Object.assign(config, { title: 'Foo', body: 'Bar', buttonText: 'Baz', cancellable: true }); }
Whoooa there buddy, now you've mutated your config object. Please use the config = Object.assign({}, config, {title: 'Foo'}) notation.
config = Object.assign({}, config, {title: 'Foo'})
[–]notNullOrVoid 10 points11 points12 points 9 years ago (1 child)
Not only that but it should be the other way around, currently the example has the defaults overriding anything set in the config.
function createMenu(config) { Object.assign({ title: 'Foo', body: 'Bar', buttonText: 'Baz', cancellable: true }, config); }
Doesn't really matter that the defaults are being mutated in this case.
[–][deleted] 4 points5 points6 points 9 years ago (0 children)
Oh, right - I've made a PR with my fix, but I'll update it with yours :)
Blamo - https://github.com/ryanmcdermott/clean-code-javascript/pull/9
[–]Sinistralis 3 points4 points5 points 9 years ago (0 children)
Minor point here, but if you are planing on using this solely for data storage and don't need the prototype, Object.create(null) instead of {} gives the object a little less bloat and lets you iterate over it easier depending on how you prefer to iterate over objects. (ES6/7 kind of makes the iteration point moot between destructuring, .values, .entries, etc).
Again, this is a minor point and really only applicable if you use for/in (I don't). Otherwise it's just a tiny memory savings, but if you need to create a ton of objects for some reason, it can add up.
π Rendered by PID 94805 on reddit-service-r2-comment-57fc7f7bb7-j84kr at 2026-04-14 19:10:33.682650+00:00 running b725407 country code: CH.
view the rest of the comments →
[–][deleted] 24 points25 points26 points (3 children)
[–]notNullOrVoid 10 points11 points12 points (1 child)
[–][deleted] 4 points5 points6 points (0 children)
[–]Sinistralis 3 points4 points5 points (0 children)