繁体   English   中英

如何在Ramda.js / lodash中使此代码更具“功能性编程”风格

[英]How can I make this code more 'functional programming' style in Ramda.js / lodash

我有这段代码:

var fn = function(fn, name) {
   this.commands.add(name, fn);
}.bind(this);

_.mapObjIndexed(fn, this.commandList);

我觉得有一种方法可以改进这段代码,使其仅一行。 我尝试了许多不同的方法,但是我对ramda.js ,我可能会缺少一些功能,这会使此操作变得更加容易和简单。

您似乎在寻找flip功能 / flip功能

_.mapObjIndexed(_.flip(this.commands.add), this.commandList);

如果需要add函数的.bind(this.commands) ,则可以使用_.bindKey (this.commands, "add")来缩短它。

如果由于参数数量而导致翻转无法正常进行,则可能不需要输入_.ary(…, 2)_.binary(…)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM