react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / js-yaml / node_modules / argparse / node_modules / lodash / function / bindKey.js
80742 viewsvar createWrapper = require('../internal/createWrapper'),1replaceHolders = require('../internal/replaceHolders'),2restParam = require('./restParam');34/** Used to compose bitmasks for wrapper metadata. */5var BIND_FLAG = 1,6BIND_KEY_FLAG = 2,7PARTIAL_FLAG = 32;89/**10* Creates a function that invokes the method at `object[key]` and prepends11* any additional `_.bindKey` arguments to those provided to the bound function.12*13* This method differs from `_.bind` by allowing bound functions to reference14* methods that may be redefined or don't yet exist.15* See [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)16* for more details.17*18* The `_.bindKey.placeholder` value, which defaults to `_` in monolithic19* builds, may be used as a placeholder for partially applied arguments.20*21* @static22* @memberOf _23* @category Function24* @param {Object} object The object the method belongs to.25* @param {string} key The key of the method.26* @param {...*} [partials] The arguments to be partially applied.27* @returns {Function} Returns the new bound function.28* @example29*30* var object = {31* 'user': 'fred',32* 'greet': function(greeting, punctuation) {33* return greeting + ' ' + this.user + punctuation;34* }35* };36*37* var bound = _.bindKey(object, 'greet', 'hi');38* bound('!');39* // => 'hi fred!'40*41* object.greet = function(greeting, punctuation) {42* return greeting + 'ya ' + this.user + punctuation;43* };44*45* bound('!');46* // => 'hiya fred!'47*48* // using placeholders49* var bound = _.bindKey(object, 'greet', _, '!');50* bound('hi');51* // => 'hiya fred!'52*/53var bindKey = restParam(function(object, key, partials) {54var bitmask = BIND_FLAG | BIND_KEY_FLAG;55if (partials.length) {56var holders = replaceHolders(partials, bindKey.placeholder);57bitmask |= PARTIAL_FLAG;58}59return createWrapper(key, bitmask, object, partials, holders);60});6162// Assign default placeholders.63bindKey.placeholder = {};6465module.exports = bindKey;666768