pulling Evgeniy Dolzhenko's patch to add _.tap, with tests

This commit is contained in:
Jeremy Ashkenas
2009-12-11 09:25:20 -05:00
parent c17879453a
commit d49196f2e7
3 changed files with 39 additions and 2 deletions

View File

@@ -495,6 +495,13 @@
return typeof obj == 'undefined';
};
// Invokes interceptor with the obj, and then returns obj.
// The primary purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain.
_.tap = function(obj, interceptor) {
interceptor(obj);
return obj;
}
// Define the isArray, isDate, isFunction, isNumber, isRegExp, and isString
// functions based on their toString identifiers.
var types = ['Array', 'Date', 'Function', 'Number', 'RegExp', 'String'];