什么是“|>”运营商在Javascript中做什么? [英] What does the "|>" operator do in Javascript?
本文介绍了什么是“|>”运营商在Javascript中做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我最近在阅读有关Javascript的内容并遇到了一些对我来说很陌生的语法:
I was reading about Javascript recently and ran into some syntax which seemed foreign to me:
const max = {a: 1, b: 2, c: 3}
|> Object.values
|> (_ => Math.max(..._))
究竟是什么 |>
在这种情况下意味着什么?
What exactly does |>
mean in such a scenario?
推荐答案
管道运营商(
|>
)是一个非标准的实验运算符(仅适用于FireFox),它将第一个操作数作为参数传递给第二个操作数(应该是是一个功能)。
The pipeline operator (
|>
) is a non-standard experimental operator (works only in FireFox), which passes its first operand as an argument to its second operand (which should be a function).
转换到这种情况,它看起来像这样:
Translated to this case, it will look like this:
const max = (_ => Math.max(..._))(
Object.values({a: 1, b: 2, c: 3})
)
console.log(max) //3
- 首先,将
{a:1,b:2,c:3}
传递给Object.values
- 然后,将结果传递给匿名函数
(_ => Math.max(..._))
- 最后,将输出分配给变量
max
- First, pass
{a: 1, b: 2, c: 3}
toObject.values
- Then, pass the result to the anonymous function
(_ => Math.max(..._))
- Finally, assign the output to variable
max
这篇关于什么是“|>”运营商在Javascript中做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文