解构函数调用
Posted
技术标签:
【中文标题】解构函数调用【英文标题】:Destructuring a function call 【发布时间】:2021-03-24 01:19:58 【问题描述】:假设如下代码:
this.props.myFunction();
EsLint 报错如下:
Must use destructuring props assignment react/destructuring-assignment
虽然目前的代码简洁明了,但如果我还想解构代码让 EsLint 开心,我该怎么做呢?
【问题讨论】:
【参考方案1】:这条规则的docs 说props
的属性在使用它们之前应该被解构,所以就这样做吧:
const myFunction = this.props;
myFunction();
【讨论】:
出于某些原因,我认为函数与属性相比会有很大不同。谢谢!以上是关于解构函数调用的主要内容,如果未能解决你的问题,请参考以下文章
Kotlin常用的 Kotlin 类 ① ( 嵌套类 | 数据类 | 数据类 copy 函数 | 数据类解构声明 operator fun component1 | 数据类运算符重载 )
Kotlin常用的 Kotlin 类 ① ( 嵌套类 | 数据类 | 数据类 copy 函数 | 数据类解构声明 operator fun component1 | 数据类运算符重载 )