我使用Dojo,并且在HTML模板中的代码之外定义了一些页面小部件。我怎么能对JSDoc说实际定义了一些this
字段?
SomePage.js
define([ "dojo/dom", "dojo/on", "dojo/_base/lang" ],
function(dom, on, lang) {
return {
init: function(){
on(this._myButton, "click", lang.hitch(this, this._foo));
},
foo: function(){
//some code here
}
}
}
});
SomePage.html
<div>
<div class="Button" data-dojo-attach-point="_myButton">
Click me!
</div>
</div>
在此示例中,JSDoc警告我this._myButton
尚未解决。它在可见范围内确实未定义,但实际上它保证由Dojo通过data-dojo-attach-point
定义。如何覆盖JSDoc并告诉他this._myButton
是否为当前模块定义? (使用Webstorm IDE)
答案 0 :(得分:1)
我有同样的问题,目前它不是自动“解决”,而是通过风格/纪律。我没有在我面前的代码,但在工作中我们正在制作这样的小部件:
define([
"dojo/declare",
"dojo/dom",
"dojo/on",
"dojo/_base/lang",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
"dijit/_WidgetsInTemplateMixin",
"dojo/text!./templates/myTemplate.html"
"dijit/form/Button" // Instantiated in template
], function(declare, dom, on, lang, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, template) {
return declare([_WidgetBase, _TemplatedMixin, WidgetsInTemplateMixin],{
templateString:template,
// Attachpoints
_myButtonWidget:null,
_someThingyNode:null,
init: function(){
on(this._myButtonWidget, "click", lang.hitch(this, this._foo));
},
foo: function(){
//some code here
}
});
});
使用myTemplate.html
之类的:
<div>
<div data-dojo-type="dijit/form/Button" data-dojo-attach-point="_myButton">
Click me!
</div>
<div data-dojo-attach-point="someThingyNode"><!-- Not a widget--></div>
</div>
主要内容应该是您在不等待Dojo在运行时创建属性的情况下创建属性。作为个人惯例,附加的dijit以“Widget”结尾,任何“vanilla”附加点都被命名为“Node”。
优点:
.js
文件.html
模板来确定您是在处理子窗口小部件还是使用vanilla DOM节点。