匿名JavaScript函数究竟是什么f => f做? [英] What exactly does the anonymous JavaScript function f => f do?

查看:103
本文介绍了匿名JavaScript函数究竟是什么f => f做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个具有函数作为参数的函数的第三方库。我正在做一些条件检查来决定是否添加一个特定的函数作为参数,在某些情况下,我不想提供一个函数。在这种情况下提供null会引发错误。

I'm using a third-party library that has a function that takes functions as arguments. I'm doing some conditional checks to decide whether or not to add a particular function as a parameter and in some cases I don't want to provide a function. Providing null in that cases throws an error.

我发现这个代码有效,但我完全不了解发生了什么。

I found this code which works, but I don't fully understand what's happening.

compose(__DEV__ ? devTools() : f => f)

f => f 相当于()=> {} 一个空的匿名函数?

Is f => f equivalent to () => {} an empty anonymous function?

推荐答案

f => f 类似*到 function(f){return f;

如此接近,但不完全符合您的预期。

So close, but not quite what you expected.

相关。他们在其他情况下非常相关。

这篇关于匿名JavaScript函数究竟是什么f => f做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆