简体   繁体   English

下面的 JavaScript 是什么意思?

[英]What's the meaning of JavaScript in below?

l = (m, n) => { if (w()) return n-1;} is one of a sample code but I want to understand the use of this in a JavaScript I have a long code which has most use of these elements can anyone help me out on this really confused on this part. l = (m, n) => { if (w()) return n-1;}是示例代码之一,但我想了解它在 JavaScript 中的使用我有一个很长的代码,它最常用这些元素任何人都可以帮助我解决这方面的问题。

I have tried on https://www.w3schools.com/js/js_arrow_function.asp but could not get exact answers.我曾在https://www.w3schools.com/js/js_arrow_function.asp 上尝试过,但无法得到确切的答案。

I have tried on some forums too but the exact search results could not be fetched.我也在一些论坛上尝试过,但无法获取确切的搜索结果。

=> stands for arrow function which was introduced in ES6. =>代表 ES6 中引入的箭头函数

So instead of typing below syntax for writing function:因此,不要输入以下语法来编写函数:

function test(m, n) {
    if (w()) return n-1;
}

The same can be written using arrow function:可以使用箭头函数编写相同的内容:

(m, n) => {
    if (w()) return n-1;
}

In your code snippet, variable l is assigned the value of above function.在您的代码片段中,变量l被分配了上述函数的值。 Your function will return n-1 based on the return of another function w() .您的函数将根据另一个函数w()的返回返回n-1

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

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