Skip to content

Instantly share code, notes, and snippets.

@robozevel
Created December 13, 2012 00:50
Show Gist options
  • Save robozevel/4273095 to your computer and use it in GitHub Desktop.
Save robozevel/4273095 to your computer and use it in GitHub Desktop.
IE7/8 JavaScript method shims using underscore.js
(function() {
function extendPrototype(Obj) {
return function(method, fn) {
if (!(method in Obj.prototype)) Obj.prototype[method] = _.isFunction(fn) ? fn : function() {
return _[method].apply(null, [this].concat(_.toArray(arguments)));
};
}
};
_.each(["indexOf", "lastIndexOf", "forEach", "map", "filter", "every", "some"], extendPrototype(Array));
extendPrototype(Function)("bind");
extendPrototype(String)("trim", function() {
return this.replace(/^\s+/, '').replace(/\s+$/, '');
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment