1 var createWrapper = require('./_createWrapper'),
2 replaceHolders = require('./_replaceHolders'),
3 rest = require('./rest');
5 /** Used to compose bitmasks for wrapper metadata. */
11 * Creates a function that invokes the method at `object[key]` and prepends
12 * any additional `_.bindKey` arguments to those provided to the bound function.
14 * This method differs from `_.bind` by allowing bound functions to reference
15 * methods that may be redefined or don't yet exist.
16 * See [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
19 * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
20 * builds, may be used as a placeholder for partially applied arguments.
25 * @param {Object} object The object to invoke the method on.
26 * @param {string} key The key of the method.
27 * @param {...*} [partials] The arguments to be partially applied.
28 * @returns {Function} Returns the new bound function.
33 * 'greet': function(greeting, punctuation) {
34 * return greeting + ' ' + this.user + punctuation;
38 * var bound = _.bindKey(object, 'greet', 'hi');
42 * object.greet = function(greeting, punctuation) {
43 * return greeting + 'ya ' + this.user + punctuation;
49 * // Bound with placeholders.
50 * var bound = _.bindKey(object, 'greet', _, '!');
54 var bindKey = rest(function(object, key, partials) {
55 var bitmask = BIND_FLAG | BIND_KEY_FLAG;
56 if (partials.length) {
57 var placeholder = bindKey.placeholder,
58 holders = replaceHolders(partials, placeholder);
60 bitmask |= PARTIAL_FLAG;
62 return createWrapper(key, bitmask, object, partials, holders);
65 // Assign default placeholders.
66 bindKey.placeholder = {};
68 module.exports = bindKey;