简体   繁体   English

意外使用逗号运算符

[英]Unexpected use of comma operator

I have following error message:我有以下错误消息:

Unexpected use of comma operator no-sequences意外使用逗号运算符无序列

This is the code:这是代码:

<Icon.Clipboard onClick={() => (

    this.handleModal("open","modify"), this.prettyPrint(JSON.stringify(res)))}
/>

Where does the problem come from?问题出在哪里?

It's the , after this.handleModal("open","modify") .在 this.handleModal("open" , "modify") 之后this.handleModal("open","modify") That arrow function should use a full function body ( { after the => and its accompanying } at the end) and a statement separator ( ; or newline) between the two function calls:该箭头函数应该在两个函数调用之间使用完整的函数体(在=>之后的{及其随附的} )和语句分隔符( ;或换行符):

<Icon.Clipboard onClick={() => {
    this.handleModal("open","modify");
    return this.prettyPrint(JSON.stringify(res));
}} />

Or more likely, you don't want that return (but that's what your code using the comma operator was doing):或者更有可能,您不希望return (但这就是您使用逗号运算符的代码所做的事情):

<Icon.Clipboard onClick={() => {
    this.handleModal("open","modify");
    this.prettyPrint(JSON.stringify(res));
}} />

The comma operator evaluates its left-hand operand, then throws that result away, evalutes its right-hand operand, and takes that as its result.逗号运算符评估其左侧操作数,然后将结果丢弃,评估其右侧操作数,并将其作为结果。 It's commonly abused as a statement separator, but it isn't one and doing so can have unintended consequences (such as returning the result of printPrint above — probably harmless in this case, but often not).它通常被滥用为语句分隔符,但它不是一个,这样做可能会产生意想不到的后果(例如返回上面printPrint的结果——在这种情况下可能是无害的,但通常不是)。

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

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