问题描述
在使用lodash时,我发现当我使用隐式链接时,它应用了快捷方式融合.
While working with lodash, I found that it applied shortcut fusion when I used implicit chaining.
$ node -e 'const _ = require("lodash"); _([1,2,3]).map(n => { console.log(n); return n }).find(n => n <= 1)'
1
但是当我将此代码段更改为使用显式链接时,它不应用快捷方式融合.
But when I changed this snippet to use explicit chaining, it doesn't apply shortcut fusion.
$ node -e 'const _ = require("lodash"); _.chain([1,2,3]).map(n => { console.log(n); return n }).find(n => n <= 1).value()'
1
2
3
如您所见,传递给map
的函数被调用了三次,而不是调用一次,这表明lodash没有应用快捷方式融合.
As you can see, a function passed to map
was called three times instead of once, which indicates lodash didn't apply shortcut fusion.
在他们的文档中,两种情况下似乎都应该应用快捷方式融合.
From their document, shortcut fusion should seem to be applied in both cases.
- 这是预期的行为吗?
- 如果可以的话,他们在文件中的何处解释这种行为?
- 是否可以通过显式链接应用快捷方式融合?
我在node.js v8.10.0上使用lodash 4.17.5.
I use lodash 4.17.5 on node.js v8.10.0.
推荐答案
我发现了一张票证在其GitHub项目上了解此问题.
I found a ticket about this issue at their GitHub project.
这篇关于使用lodash的显式链接不应用快捷方式融合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!