拥有此代码:
function Element() {
this.name = "yay";
}
Element.prototype.extend = function(object) {
if (object instanceof Object) {
for (var n in object) {
if (object.hasOwnProperty(n)) {
this[n] = object[n];
}
}
}
};
var el = new Element();
el.extend({
update: function() {
console.log(this.name);
}
});
我希望WebStorm知道update()
this
是Element
的一个实例,但我真的不知道该怎么做。
我达到的最大值是:
el.extend({
/**
* @this Element
*/
update: function() {
console.log(this.name);
}
});
但我不想在每个extend()
中都这样做。
还发现了这个:
/**
* @typedef {Object} FunctionExtend
*/
/**
* @param {FunctionExtend} object
*/
Element.prototype.extend = function(object) {
[...]
但是我陷入了困境:
FunctionExtend
具有未定义的参数数量。@parameter
是否为回调。@this
是什么。答案 0 :(得分:2)
Extending prototypes to begin with is generally a Bad Idea™, and it does not play well with write-time documentation tools like JSDoc.
You will probably have no choice but to document every function individually.