10

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!

1 Answer 1

17

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

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

Lodash mixin

Sign up to request clarification or add additional context in comments.

3 Comments

If I require('lodash') in one file and create this mixin, will it be available other places I require() it?
and then how will that function be used? you didn't say
that function is then use as _.myFunction (or whatever you named the mixin)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.