简体   繁体   English

简单的JS箭头功能:参数列表后缺少括号:为什么?

[英]Simple JS Arrow Function: Missing Parenthesis After Argument List: Why?

This simple javascript arrow function results in a parser error. 这个简单的JavaScript箭头功能会导致解析器错误。 The syntax seems consistent with all the examples I've seen. 语法似乎与我所看到的所有示例都一致。 What is the syntax error and how do I correct it? 什么是语法错误,我该如何纠正?

var things = [];
things.push("a");
var containsA = things.some(t => t === "a");

The error: Uncaught SyntaxError: missing ) after argument list 参数列表后出现错误:未捕获的SyntaxError:缺少)

Your code produces a valid arrow function : 您的代码产生一个有效的箭头函数

t => t === "a"

However, arrow functions are an experimental technology, part of the ECMAScript 6 proposal, which currently is still a draft. 但是,箭头功能是一项实验性技术,属于ECMAScript 6提议的一部分,该提议目前仍是草案。 Therefore, not all browsers have implemented them yet. 因此,并非所有浏览器都已实现它们。

Among the major ones, only Firefox has. 在主要版本中,只有Firefox具有。 If you attempt to use them on Chrome, you will get an error. 如果尝试在Chrome上使用它们,则会收到错误消息。

Currently Arrow Functions are supported by FireFox only. 当前,只有FireFox支持Arrow Functions

From MDN : MDN

浏览器与箭头功能的兼容性

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

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