Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 这个代码snipe是做什么的,还是仅仅是一个错误_Reactjs_React Props - Fatal编程技术网

Reactjs 这个代码snipe是做什么的,还是仅仅是一个错误

Reactjs 这个代码snipe是做什么的,还是仅仅是一个错误,reactjs,react-props,Reactjs,React Props,我学习Reactjs并阅读了大量代码,但我无法理解这一点。 这是代码中的错误还是它做了什么 我是说这句话: this.props.onEnd && this.props.onEnd(); 我知道onEnd()是对父级的回调,但它是如何工作的? 代码 这相当于说: if (this.props.onEnd != null) { // validate not null or undefined this.props.onEnd(); // exec

我学习Reactjs并阅读了大量代码,但我无法理解这一点。
这是代码中的错误还是它做了什么

我是说这句话:

this.props.onEnd && this.props.onEnd();
我知道
onEnd()
是对父级的回调,但它是如何工作的? 代码


这相当于说:

if (this.props.onEnd != null) {   // validate not null or undefined
    this.props.onEnd();           // execute function
}
当表达如下时:

this.props.onEnd && this.props.onEnd();
如果
oned
为空或未定义,则表达式将短路。如果是,则表达式的逻辑计算结果为:

false && this.props.onEnd()

在这种情况下,由于
false&&作为互联网搜索。

这相当于说:

if (this.props.onEnd != null) {   // validate not null or undefined
    this.props.onEnd();           // execute function
}
当表达如下时:

this.props.onEnd && this.props.onEnd();
如果
oned
为空或未定义,则表达式将短路。如果是,则表达式的逻辑计算结果为:

false && this.props.onEnd()

在这种情况下,由于
false&&作为互联网搜索。

我将代码更改为
const{onEnd}=this.props;onEnd&&onEnd()然后Eslint又不高兴了“期待一个赋值或函数调用,而看到了一个表达式。Eslint没有未使用的表达式”Eslint不喜欢短路,但我喜欢!lolI将代码更改为
const{onEnd}=this.props;onEnd&&onEnd()然后Eslint又不高兴了“期待一个赋值或函数调用,而看到了一个表达式。Eslint没有未使用的表达式”Eslint不喜欢短路,但我喜欢!英雄联盟