簡體   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