Live data from Hacker News

Lists of JavaScript methods which you can use natively

github.com

31–40 of 162 posts

Re: Lists of JavaScript methods which you can use natively

#31
post #11

There's a huge gotcha: _.map, _.forech, ... can iterate over objects (often used as associative arrays) - Native map can't. At some point you'll need lodash and co again - at least for convinience.

Object.keys() is rather well supported these days though.

Related:

for (var key of Object.keys(imps)) { }

I figured that would work with babel-2015 and it did work on Chrome and Safari but on Firefox visitors were getting:

Symbol.Iterator undefined

You need http://babeljs.io/docs/plugins/transform-es2015-for-of/ as well.

So there is much less risk in using _.each(imps, (value, key) => and not having to discover what you don't know.

I also added Firefox to the unit tests after that.

Re: Lists of JavaScript methods which you can use natively

#32
post #23

Earlier quoted context omitted.

Object.keys() is rather well supported these days though.

Yes, but means that you need to implement map, foreach, filter yourself. So you might be better off with lodash.

I think he's referring to `Object.keys(object).reduce`. We polyfill `Object.entries` so we do `Object.entries(object).reduce((result, [key, value]) => ...)`

Re: Lists of JavaScript methods which you can use natively

#33
post #11

There's a huge gotcha: _.map, _.forech, ... can iterate over objects (often used as associative arrays) - Native map can't. At some point you'll need lodash and co again - at least for convinience.

Yup, this is my biggest issue with JavaScript's built-in functional utilities. It just totally ignores treating objects like dictionaries/maps. Even ES6 Maps/Sets lack functional features.

There's a strawman proposal out there to solve this but until then I'll be sticking with Lodash: https://github.com/leebyron/ecmascript-iterator-hof

Re: Lists of JavaScript methods which you can use natively

#34
post #11

There's a huge gotcha: _.map, _.forech, ... can iterate over objects (often used as associative arrays) - Native map can't. At some point you'll need lodash and co again - at least for convinience.

I agree, this is the sole reason I use atleast underscore in every project.

Re: Lists of JavaScript methods which you can use natively

#35
post #18

Earlier quoted context omitted.

If you just use lodash from a CDN, many, many users will already have it. If you make a custom build, then everyone has to download.

Didn't someone do a study and found that cache hit rates for CDNs were in the 10-20% range? You might be better off bundling lodash and tree shaking everything you don't actually use away.

And it will also lead to the site not working out-of-the-box for privacy-conscious people like me who block third-party JS by default.

Re: Lists of JavaScript methods which you can use natively

#37

Earlier quoted context omitted.

Didn't someone do a study and found that cache hit rates for CDNs were in the 10-20% range? You might be better off bundling lodash and tree shaking everything you don't actually use away.

And it will also lead to the site not working out-of-the-box for privacy-conscious people like me who block third-party JS by default.

Well you can avoid that with an inline script that checks for it and includes it from a local path if it fails.

But that's just more waiting, and you still end up downloading the ENTIRE script (unless you get REALLY fancy with webpack in a way I don't even want to think about...)

Post reply on HN