SyntaxError:无效的箭头函数参数(箭头函数周围的括号可能有帮助)(SyntaxError: invalid arrow

编程入门 行业动态 更新时间:2024-10-16 20:28:12
SyntaxError:无效的箭头函数参数(箭头函数周围的括号可能有帮助)(SyntaxError: invalid arrow-function arguments (parentheses around the arrow-function may help))

这样的代码会生成错误:

if(hr>t1[0]||(hr==t1[0]&&min=>t1[1]) && hr<t2[0]||(hr==t2[0]&&min<t2[1]))

错误:

SyntaxError:无效的箭头函数参数(箭头函数周围的括号可能有帮助)

它是什么意思,它是怎么发生的? Google搜索此错误非常无用。

编辑:

似乎是由使用=>而不是>= 。 但是我仍然很好奇为什么错误的表达是这样的,箭头函数应该是什么。

编辑2。

首先,我没有意识到这实际上可能是特定于浏览器的问题。 另外,我没有意识到这些天,人们在浏览器上下文以外的地方使用JS。 所以,为了说清楚,我的浏览器是Mozilla Firefox 25.0.1。

Such code will generate an error:

if(hr>t1[0]||(hr==t1[0]&&min=>t1[1]) && hr<t2[0]||(hr==t2[0]&&min<t2[1]))

The error:

SyntaxError: invalid arrow-function arguments (parentheses around the arrow-function may help)

What does it mean, how did it happen? Google searches for this error are desperately useless.

Edit:

Seems to be caused by using => instead of >=. But I'm still curious why is the error formulated like this, and what the arrow function is supposed to be.

Edit 2.

First, I didn't realise that this could actually be browser specific issue. Also, I didn't realise that these days, people use JS in other places than browser context. So, to make that clear, my browser is Mozilla Firefox 25.0.1.

最满意答案

=>应该>= (大于或等于)


箭头功能是一个coffeescript(和ES6 !)功能 - 这个:

f = x => this.y * x

相当于:

f = function(x) { return this.y * x; }.bind(this)

=> should be >= (more than or equal)


An arrow-function is a coffeescript (and ES6!) feature - this:

f = x => this.y * x

Is equivalent to:

f = function(x) { return this.y * x; }.bind(this)

更多推荐

本文发布于:2023-07-06 07:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047407.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:箭头   函数   能有   括号   参数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!