As is known, Internet Explorer (at least <= 8) does not support several javascript Array functions (indexOf, filter, etc). This stackoverflow answer provides some decent implementations of most of these missing Array functions.
My question: is it preferable to provide implementations like those in the answer for your website or simply rely on an external library (jQuery, etc)?
Is there a best practice? I’m looking for insight from those with more practical experience than I with this situation.
The lack of dependency on an external library is always a plus (although they’re largely ubiquitous in most cases). But there’s no guarantee that any custom implementation will cover ALL edge cases and it introduces something to maintain.
best practice is probably using the es5-shim which lets you use javascript in all browsers as if it was fully ECMAScript 5 compatible (with a few limitations, for example the second param of
Object.createcan’t be emulated).This has the sheer advantage that it only acts on browsers that lack such extensions, so modern browsers will use the built-in optimized versions of the code.
Also, you avoid leveraging on an external library that defines their own spec, which in case of jQuery is kinda broken like
$.eachhaving the params inverted from what the spec says forArray.prototype.forEach, or weird naming conventions like$.proxyfor whatFunction.prototype.binddoes.