[英]i can't seem to get my hover effects to work on button. have tried many tips
[英]I have read many resources and tried to find answer to my question but couldn't. I'm asking about how chaining the higher order functions work
所以,這是簡單的箭頭 function,但我不明白 sth、sth1 等如何工作或者它們是什么? 它們是 arguments 還是 function 還是只是值? 或者可以是他們兩個? 如果是這樣,這個鏈接是如何工作的,請幫助我。
const someFunction = sth => sth1 => sth2 => {
// do something if needed
}
你所擁有的並不是真正的鏈接箭頭函數(或currying ),而是一種將相同的 function 一次分配給多個標識符的非常混亂的方式。
=
從右到左求值,整個表達式求值為右側的值。 賦值的最右邊是箭頭 function 表達式:
sth2 => {
// do something if needed
}
在那里, sth2
是一個參數。
箭頭 function 被分配給一個名為sth1
的標識符:
sth1 = sth2 => { ...
sth1
還沒有被宣布。 如果您處於嚴格模式,這將拋出錯誤,或者它將在全局 object 上放置一個屬性,在草率模式下箭頭值為 function。
然后,整個部分的計算結果為箭頭 function,並且該過程對sth
本身重復。
sth = theArrowFunction
最后,該賦值的計算結果為箭頭 function,並創建包含箭頭 function 的標識符someFunction
。
完成同一件事的一種不那么令人困惑的方法(在嚴格或草率模式下)是
sth1 = sth2 => {
// do something if needed
};
sth = sth1;
const someFunction = sth1;
但是您確定那是您使用的確切代碼嗎? 如果您的代碼實際上是
const someFunction = sth => sth1 => sth2 => {
// do something if needed
}
那么這不是鏈式賦值,而是柯里化,其中sth
、 sth1
和sth2
對於不同的函數都是 arguments 。
這相當於:
const myFun = x => {...}
const sth1 = myFun
const sth = sth1
const someFunction = sth
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.