I'm using _.bind from underscore.js, however it is not working within IE8/9.
I understand MDN has a work around (MDN Polyfill - but not sure if this can be applied to the underscore library, or whether there is a fix for this in underscore itself
An example of what I'm trying to achieve is:
window.onload = _.bind(function() {
this.product.quantityListing();
}, this);
EDIT: I'm using an instance of _.bind else where and it works in IE8 - however it is just not working when I want to check the window has loaded in IE.
_.bind
and the Function#bind
shim from MDN do essentially the same thing. If you use the MDN method, you need not use the Underscore.js method.
You would use the MDN method like this:
window.onload = (function() {
this.product.quantityListing();
}).bind(this);
On the other hand, if you use the MDN shim before you include Underscore in your page, Underscore will use the shimmed version if necessary.
So if you include the shim before Underscore, you can use whichever you prefer. Personally I'd stick with using Function#bind
, because it has (very slightly) better performance in browsers that natively support it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With