Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 369
user687554 Avatar asked Jun 29 '14 11:06

user687554


1 Answers

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

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

Lodash mixin

like image 65
Dmitry Zaets Avatar answered Oct 24 '22 22:10

Dmitry Zaets