user687554
user687554

Reputation: 11131

Adding custom functions to lodash

I've added lodash to my project as it adds some great functions. However, I would like to add a utility function. Is there a way I can add my function to the '_.' syntax? In other words, I'd love to be able to call '_.myFunction(someParam);'

Is there a way to extend lodash in JavaScript? If so, how?

Thanks!

Upvotes: 10

Views: 4869

Answers (1)

Dmitry Zaets
Dmitry Zaets

Reputation: 3277

You can use _.mixin function to add your custom function:

_.mixin({
  'myFunction' : function(someParam) {
    //body of function
  }
});

Lodash mixin

Upvotes: 17

Related Questions