如何正确记录扩展 String 对象原型(prototype)的函数?例如:
if (!String.prototype.format) {
/**
* @name String.prototype.format
* Replaces symbols like {0}, {1} in a string with the values from the arguments.
*/
String.prototype.format = function () {
var args = arguments;
return this.replace(/{(\d+)}/g, function (match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
};
}
我尝试了带或不带 @function 和 @name 注释的情况。
它不起作用,因为 Visual Studio 2017 不会像添加 JSDoc 注释时通常那样开始显示带有函数描述的工具提示。
最佳答案
这个可以吗
if (!String.prototype.format) {
/**
* @namespace String
*/
/**
* @memberof String
* @name String#format
* @function
* Replaces symbols like {0}, {1} in a string with the values from the arguments.
*/
String.prototype.format = function () {
var args = arguments;
return this.replace(/{(\d+)}/g, function (match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
};
}
关于javascript - 如何为修改 String 原型(prototype)的内联函数正确编写 JSDoc?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45497670/