1 var baseCallback = require('../internal/baseCallback'),
2 isIterateeCall = require('../internal/isIterateeCall'),
3 isObjectLike = require('../internal/isObjectLike'),
4 matches = require('./matches');
7 * Creates a function that invokes `func` with the `this` binding of `thisArg`
8 * and arguments of the created function. If `func` is a property name the
9 * created callback returns the property value for a given element. If `func`
10 * is an object the created callback returns `true` for elements that contain
11 * the equivalent object properties, otherwise it returns `false`.
17 * @param {*} [func=_.identity] The value to convert to a callback.
18 * @param {*} [thisArg] The `this` binding of `func`.
19 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
20 * @returns {Function} Returns the callback.
24 * { 'user': 'barney', 'age': 36 },
25 * { 'user': 'fred', 'age': 40 }
28 * // wrap to create custom callback shorthands
29 * _.callback = _.wrap(_.callback, function(callback, func, thisArg) {
30 * var match = /^(.+?)__([gl]t)(.+)$/.exec(func);
32 * return callback(func, thisArg);
34 * return function(object) {
35 * return match[2] == 'gt'
36 * ? object[match[1]] > match[3]
37 * : object[match[1]] < match[3];
41 * _.filter(users, 'age__gt36');
42 * // => [{ 'user': 'fred', 'age': 40 }]
44 function callback(func, thisArg, guard) {
45 if (guard && isIterateeCall(func, thisArg, guard)) {
48 return isObjectLike(func)
50 : baseCallback(func, thisArg);
53 module.exports = callback;