Created
November 6, 2014 14:04
-
-
Save james-gardner/adcbd28f5035b263b04b to your computer and use it in GitHub Desktop.
Cherry pick and pre-bind underscore methods (borrowed from backbone)
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
var Url = function (url) { | |
this._url = url; | |
}; | |
_.extend(Url.prototype, { | |
/* more prescriptive methods */ | |
}); | |
var methods = ['forEach', 'each', 'map', 'find', 'detect', 'filter', | |
'select', 'reject', 'every', 'all', 'some', 'any', 'include', | |
'contains', 'invoke', 'toArray', 'first', 'initial', 'rest', | |
'last', 'without', 'isEmpty', 'pluck']; | |
_.each(methods, function(method) { | |
Url.prototype[method] = function() { | |
var fragments = this._url.split('/'); | |
var args = [fragments].concat(_.toArray(arguments)); | |
return _[method].apply(_, args); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment