gpt4 book ai didi

lodash - Lodash链功能的调试

转载 作者:行者123 更新时间:2023-12-02 03:24:11 27 4
gpt4 key购买 nike

如何在浏览器中调试lodash链函数。

例如:

if (_.size(_.values(_.omit(this.user, 'language')).filter(Boolean)) < 2)

如果我们想调试_.omit(this.user, 'language'),然后使用另一个函数_.values()来调试最终结果,如下所示举个例子,应该做什么。

我尝试搜索,但只能找到 console.log,但如果我们想直接在浏览器中调试,我们该怎么做。

最佳答案

链函数和 lodash 序列通常通过 _.tap 进行“调试”或“利用”或_.thru :

tap: This method invokes interceptor and returns value. The interceptor is invoked with one argument; (value). The purpose of this method is to "tap into" a method chain sequence in order to modify intermediate results.

所以像这样:

const obj = { name: 'Ace', language: 'English', age: 3 }

const result = _(obj)
.tap(x => console.log(x))
.omit('language')
.tap(x => console.log(x))
.omit('age')
.tap(x=> console.log(x))
.value()
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.10/lodash.min.js"></script>

thru: This method is like _.tap except that it returns the result of interceptor. The purpose of this method is to "pass thru" values replacing intermediate results in a method chain sequence.

关于lodash - Lodash链功能的调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53870634/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com