【发布时间】:2018-08-03 19:44:51
【问题描述】:
当我们在 React 中使用它时,我试图了解各个函数调用是如何工作的
假设我们有两个这样的函数
const something = () => {
//something
}
function something1 () {
//something
}
到目前为止,我已经看到它们以三种不同的方式被调用
喜欢
{this.something}
this.something()
(() => something)
所以我的主要问题是它们有何不同?比如被叫什么时候,有没有其他方法可以叫他们(这里没有提到)?
【问题讨论】:
-
super是关键字,不能用作标识符。{this.something}和(() => something)都没有调用函数,第一个又是无效语法。 -
您是 JavaScript 新手吗?你确定你应该在学习语言基础之前直接进入 react 吗?
-
{this.something}使用 JSX javascript 代码转义语法(即花括号)传递this.something引用的任何内容;this.something()调用this.something引用的函数;(() => something)是一个箭头函数,执行时返回something引用的任何内容。也许this tutorial会对你有所帮助。 -
@ASDFGerte
{this.something}在 JSX 中用于转义代码。 -
这取决于你想要做什么,这个问题可能是相关的,stackoverflow.com/questions/45881670/…。
标签: javascript reactjs