定义函数 return 类型,以便在编写函数调用时显示在工具提示中
Define a functions return type so it'll be shown in the tooltip when writing a function call
我希望能够设置函数 return 类型,以便我的 IDE 可以应用 Intellisense。
例如我有一个函数,它从中获取一个对象和 creates/returns 一个 HTMLElement。
当我这样调用该函数时,我希望这样:
var myElement = document.createElementWithProperties({elementType: 'div', id: 'myElement',style:{background: 'blue'}});
在下一行,当我输入 "myElement." 时,它会建议我,例如 appendChild。
您可以使用 JSDoc 文档块来装饰您的函数。例如这样的事情:
/**
* Creates an element with the specified properties.
*
* @param {object} The properties to create the element with.
* @return {HTMLElement} The HTML element.
*/
function createElementWithProperties(obj) {
// Do stuff!
}
注意:在 Visual Studio 代码中,当扩展本机文档对象时,这似乎不起作用,但作为独立函数或作为用户定义对象的一部分应该可以正常工作。
我希望能够设置函数 return 类型,以便我的 IDE 可以应用 Intellisense。
例如我有一个函数,它从中获取一个对象和 creates/returns 一个 HTMLElement。 当我这样调用该函数时,我希望这样:
var myElement = document.createElementWithProperties({elementType: 'div', id: 'myElement',style:{background: 'blue'}});
在下一行,当我输入 "myElement." 时,它会建议我,例如 appendChild。
您可以使用 JSDoc 文档块来装饰您的函数。例如这样的事情:
/**
* Creates an element with the specified properties.
*
* @param {object} The properties to create the element with.
* @return {HTMLElement} The HTML element.
*/
function createElementWithProperties(obj) {
// Do stuff!
}
注意:在 Visual Studio 代码中,当扩展本机文档对象时,这似乎不起作用,但作为独立函数或作为用户定义对象的一部分应该可以正常工作。