Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

es5-shim and underscore.js?

I have both es5-shim.js and underscore.js in my JavaScript project.

es5-shim.js just add some javascript native functions like reduce and some on arrays for Internet Explorer and some old browsers. underscore.js add the same thing (but with a different syntax) and many more thing (utility functions on objects and arrays).

But, if the functions added by es5-shim exists, underscore.js use them.

So, on a "recent" browser like Firefox or Chrome, underscore.js use the native functions of the browser. I think it's better than a pure javascript function. But on Internet Explorer, underscore.js use the es5-shim functions. If I remove es5-shim.js, underscore.js use its own functions.

Any advice on that ? Should i remove es5-shim from my project and only use underscore.js ? Or should i let underscore.js use es5-shim's functions ?

like image 400
Magus Avatar asked Dec 08 '22 19:12

Magus


1 Answers

I disagree with @ganeshi's answer.

If your primary use of Underscore is things that already come with ES5 like reduce() and some() then I suggest you remove underscore.js.

If you code to ES5 methods now, you can simply remove ES5-shim when you no longer support IE8 or Firefox 3.

If you use underscore now, then when you no longer support IE8 or Firefox 3 you still will carry an extra copy of a large amount of things most browsers already provide.

like image 147
mikemaccana Avatar answered Dec 20 '22 15:12

mikemaccana