Created
March 19, 2013 15:16
-
-
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…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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