4 ms·
obj = Object.create(null) obj = {} is exactly the same as obj = {} I would also do `Object.keys().forEach()`.
by snek 7y ago
obj = Object.create(null)
obj = {}
is exactly the same as
obj = {}
I would also do `Object.keys().forEach()`.
- sbr464 7y agoIt’s not. The null version won’t have methods like hasOwnProperty etc. If it wasn’t clear, i was mentioning 2 ways of initializing, not that you should reassign immediately.
- sbr464 7y agoI see a lot of people accessing a map/dictionary using the “for (key in)” pattern, not realizing they are inheriting any method/prototype names along with their basic dictionary they’ve defined. Using Object.create(null) is an easy way to not only save memory, but reduce issues if using dynamic key names. https://stackoverflow.com/questions/500504/why-is-using-for-in-with-array-iteration-a-bad-idea/500531#500531 https://stackoverflow.com/questions/500504/why-is-using-for-...