loverajoel / jstips

This is about useful JS tips!
http://jstips.co
GNU General Public License v3.0
12.5k stars 803 forks source link

Hash maps with no side effects #420

Closed bhaskarmelkani closed 7 years ago

bhaskarmelkani commented 7 years ago

Hash maps with no side effects

TL;DR;

Create hash maps(without side effects) using Object.create(null)

Username

@bhaskarmelkani

Extra

kurtextrem commented 7 years ago

However, watch the performance: https://jsperf.com/object-create-null-vs-literal/27 Using ES6's Map might be even more performant.

zenopopovici commented 7 years ago

This should be merged. It's a good tip. :shipit:

bhaskarmelkani commented 7 years ago

Any update on this ?

zenopopovici commented 7 years ago

@loverajoel ?

bhaskarmelkani commented 7 years ago

Snooze :)

0x1eef commented 7 years ago

why does the example use let ? there's no reassignment, const feels more appropriate. a shout out to Map seems relevant here too. there's a shout at the very end, to Map and friends.

zenopopovici commented 7 years ago

Guys can we merge this? @loverajoel, @sjfkai, @neighborhood999, @aschelstraete

sjfkai commented 7 years ago

Looks good to me 👍

0x1eef commented 7 years ago

let isn't used anymore :+1:

0x1eef commented 7 years ago

oh, maybe you meant let is less confusing? could be, not sure. probably doesn't matter much. i think eventually, as browsers support 'const' and 'let' natively, optimisations might be applied if it is known a "variable" cannot be reassigned. so probably a good practice to not ask for reassignment if it is not needed.

neighborhood999 commented 7 years ago

@r-obert Thanks for your explaining!

zenopopovici commented 7 years ago

Guys: I don't know exactly how the merge must be done, we should move ahead without Joel if he's not available.

bhaskarmelkani commented 7 years ago

I guess its not a big topic to discuss, so we should close(merge/not merge) and move forward. :)

0x1eef commented 7 years ago

:shipit: ⏲

zenopopovici commented 7 years ago

First time I merge a tip. Hopefully all goes well :)

zenopopovici commented 7 years ago

Some issues. Correcting them now.

zenopopovici commented 7 years ago

Success.

bhaskarmelkani commented 7 years ago

👍