我試圖在javascript中記錄輸入參數到一個函數,但我無法解決如何在jsdoc中執行它。jsdoc和vscode:記錄一個函數作爲參數傳遞給另一個函數
我看了一下jsdoc文檔,它建議使用@callback
評論是必需的,但Visual Studio代碼(vscode)不會按照屏幕截圖來突出顯示它。
用於location
參數的智能感知表明,它的類型any
而非locator
類型(具有id
一個參數,它返回一個Location
的函數)的。
示例代碼顯示了一個函數調用作爲參數傳遞的函數:
class Location {
constructor(position, count) {
this.position = position;
this.count = count;
}
}
const items = {
'USB Cable': new Location('Desk Drawer', 123),
Keyboard: new Location('Desk Surface', 1),
};
/**
* A locater.
* @param {string} id
* @returns {Location}
*/
const locaterA = id => items[id];
/**
* Finds the item by its unique id.
* @callback locater
* @param {string} id
* @returns {Location}
*/
/**
* Attempt to find the item with the given locater.
* @param {string} id
* @param {locater} locater
*/
const locate = (id, locater) => locater(id);
const result = locate('USB Cable', locaterA);
console.log(result);
這是與我在做什麼,不vsdoc配套使用的情況下,或vscode問題不支持它?