在Javascript函数中使用两个或多个箭头

问题描述 投票:0回答:2

我试图完全理解函数中两个或更多箭头的用法。我将如何使用'function'而不是'=>'重写以下内容。这可以帮助我掌握它]

 export const fetchPosts = () => async dispatch => {
  const response = await jsonPlaceholder.get('/posts')
  dispatch ({type: 'FETCH_POSTS', payload: response.data})
}
javascript
2个回答
2
投票

我将如何使用'function'而不是'=>'重写以下内容>

您共享的代码是一个函数,它将返回另一个函数。转换为常规函数后,它看起来像这样:

function fetchPosts () {
  return async function (dispatch) {
    const response = await jsonPlaceholder.get('/posts')
    dispatch ({type: 'FETCH_POSTS', payload: response.data})
  }
}
    

0
投票

好它不仅与箭头功能一起使用,而且还在创建一个承诺。我相信这会使初学者更加困惑。

© www.soinside.com 2019 - 2024. All rights reserved.