我正在使用 John Resig's Simple JavaScript Inhertance 定义类并用 JSDoc 的 @lends
记录它们和 @constructs
注释,但 NetBeans 不提供代码完成功能。这适用于我使用 namespace 定义的模块因为我直接引用它们。这是一个简单类的示例:
MyClass = Class.extend(
/** @lends MyClass.prototype */
{
/** @constructs */
init: function () {
console.log('init');
},
foo: function () {
console.log('foo');
}
}
);
var c = new MyClass();
c. <-- ctrl-space only shows built-in methods like hasOwnProperty() and toString()
有谁知道记录这些类以便在 NetBeans 中使用代码完成的方法吗?
最佳答案
NetBeans 仍然不支持 @lends
、@constructs
、@memborOf
或类似的标签。它们是为 7.4 和 8.0 设置的,但我认为它们不会很快实现,因为它们是从 7.0 左右开始报告的。两个中的第二个 workarounds将通过首先将包含方法的(以前)匿名对象分配给类来与 Class.extend()
一起工作。
原型(prototype)
/** @class */
var Canine;
Canine = function() {};
Canine.prototype = props;
/** @type Canine */ var canine = new Canine();
匿名对象
/** @class */
var Feline = {
purr: function() { console.log('meow'); },
fall: function() { console.log('landed on feet'); }
};
Feline = create(Feline);
/** @type Feline */ var feline = new Feline();
注意:即使在 NetBeans 7.4 补丁 1 中没有 @type
注释也能正常工作。
关于javascript - 记录使用简单 JavaScript 继承定义的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10974568/