最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Adding custom functions to lodash - Stack Overflow

programmeradmin4浏览0评论

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!

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!

Share Improve this question asked Jun 29, 2014 at 11:36 user687554user687554 11.1k26 gold badges81 silver badges142 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 17

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

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

Lodash mixin

发布评论

评论列表(0)

  1. 暂无评论