我無法理解某些功能及其介面。IE:
ReadonlyArray<unknown>.map(
callbackfn: (value: unknown, index: number, array: unknown[]) => unknown,
thisArg?: any): unknown[]
這是當我將滑鼠懸停在.map()函式上時 Webstorm 顯示的內容。我知道.map()將指定的回呼函式作為引數,但是做什么=> unknown和thisArg?: any代表什么?
同樣,當我將滑鼠懸停在forEach()函式上時,彈出視窗如下所示:
ReadonlyArray<unknown>.forEach(
callbackfn: (value: unknown, index: number, array: unknown[]) => void,
thisArg?: any): void
forEach 也有一個回呼函式作為引數,但是=> void, thisArg?: any): void代表什么呢?
uj5u.com熱心網友回復:
// the `.map` function is member of the generic type ReadonlyArray<unknown>. Where unknown is the type of the elements of the array
ReadonlyArray<unknown>.map(
// first argument is a callback function. The first argument of the callback is value, of type unknown, the second is index of type number, and so on
callbackfn: (value: unknown, index: number, array: unknown[])
// this parts means that the callback should return a value of type unknown
=> unknown,
// .map takes a second arguments called thisArg of any type. The ? means that the argument is optional
thisArg?: any)
// .map returns an array of type unknown
: unknown[]
型別未知,因為它取決于.map應用的陣列中存在的元素的型別。如果是物件陣列,則未知型別為object
類似地,forEach接受第一個引數是回呼。但是回呼不回傳任何內容,因此您有=> void.
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/311119.html
標籤:javascript 网络风暴
上一篇:過濾帶有陣列的物件
