我试图在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问题不支持它?