Kaustubh Karkare (2016-01-30T19:47:31.000Z)
kaustubh.karkare at gmail.com (2016-01-30T19:51:46.896Z)
> Not all objects are used as maps, and when using with map we often use `Object.create(null)`, so adding to prototype is definitely a bad idea. - Much like we're forced to invoke the prototype directly like (in functions & NodeLists) `Array.prototype.slice.call(arguments)`, an argument could be made that one should need invoke `Object.prototype.map.call(objWithoutPrototype, mapFn)`. - My main issue with static methods on the object is the lack of consistency with the array format. But given that we already have `Object.keys` and `Object.values`, there's already precedent for this (plus the argument about breaking legacy frameworks). Note that this methods should be on the `Map.prototype` at least (given `Map.prototype.keys/values` exist), since this argument doesn't apply in that case. > As for whether we should make them static methods of Object, I personally don't think this is very useful. Using a for-in loop is enough in my opinion. For-in loops result in unnecessary verbosity, specially in codebases that optimize for readability. Comparing something like: ``` const normalizedGrey = colors .map(c => (c.red + c.green + c.blue) / 3) .filter(g => g < someThreshold) .map(g => (g - min) / (max - min)); ``` vs ``` let normalizedGrey = {}; for (var color in colors) { let c = colors[color]; let g = (c.red + c.green + c.blue) / 3; if (g < someThreshold) { normalizedGrey[color] = (g - min) / (max - min); } } ``` The latter has more lines/bytes and is harder to read.