How to use the bindAll function from lodash

Find comprehensive JavaScript lodash.bindAll code examples handpicked from public code repositorys.

6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
 * var view = {
 *   'label': 'docs',
 *   'onClick': function() { console.log('clicked ' + this.label); }
 * };
 *
 * _.bindAll(view);
 * jQuery('#docs').on('click', view.onClick);
 * // => logs 'clicked docs', when the button is clicked
 */
function bindAll(object) {
fork icon73
star icon711
watch icon29

31
32
33
34
35
36
37
38
39
40
module.exports.before              = _.before;
module.exports.best                = _.best;
module.exports.binPick             = _.binPick;
module.exports.binary              = _.binary;
module.exports.bind                = _.bind;
module.exports.bindAll             = _.bindAll;
module.exports.bindKey             = _.bindKey;
module.exports.bitwiseAnd          = _.bitwiseAnd;
module.exports.bitwiseLeft         = _.bitwiseLeft;
module.exports.bitwiseNot          = _.bitwiseNot;
fork icon19
star icon122
watch icon0

+ 92 other calls in file

2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
_.walk = function(traversalStrategy) {
  var walker = _.clone(exports);

  // Bind all of the public functions in the walker to itself. This allows
  // the traversal strategy to be dynamically scoped.
  _.bindAll.apply(null, [walker].concat(_.keys(walker)));

  walker._traversalStrategy = traversalStrategy || defaultTraversal;
  return walker;
};
fork icon3
star icon2
watch icon1

+ 117 other calls in file

880
881
882
883
884
885
886
887
888
889
890
891
892
// Util


const attempt = _.attempt(function() { return _.divide(1, 0); });
console.log(attempt); // => [Error: Divide by zero.]


const bindAll = _.bindAll(object, ['increment', 'square']);
console.log(bindAll); // => { 'increment': [Function: increment], 'square': [Function: square] }


const cond = _.cond([
    [_.matches({ 'a': 1 }),           _.constant('matches A')],
fork icon0
star icon4
watch icon0

+ 15 other calls in file

335
336
337
338
339
340
341
      })
    })
  },
}


module.exports = _.bindAll(deploy, _.functions(deploy))
fork icon0
star icon0
watch icon0

Other functions in lodash

Sorted by popularity

function icon

lodash.get is the most popular function in lodash (7670 examples)