Skip to content

Instantly share code, notes, and snippets.

@osartun
Created March 19, 2013 15:16
Show Gist options
  • Save osartun/5196962 to your computer and use it in GitHub Desktop.
Save osartun/5196962 to your computer and use it in GitHub Desktop.
UnderscoreJS-Mixin: Redefine the order of your arguments. Useful for functions which get called by different callers (i.e. DOM-Eventlistener and Backbone-Eventlistener) with different arguments orders. Doesn't change the "this"-context. Use it like this: var funcB = _.arrange(funcA, 1,0,2) funcA(1,2,3) => arguments order: 1,2,3 funcB(1,2,3) => a…
(function (_) {
_.mixin({
arrange : function(func) {
var newOrder = [].slice.call(arguments, 1), arranged, i,l;
return function() {
for (arranged = [], i=0, l=newOrder.length; i<l; i++)
arranged.push(arguments[newOrder[i]]);
return func.apply(this, arranged);
}
}
});
})(window._)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment