javascript - How can I specify the type of the "this" value for a closure in JetBrains IDEs? -
jetbrains has old blog post jsdoc annotations explains how inform ide of variable types http://blog.jetbrains.com/webide/2012/10/validating-javascript-code-with-jsdoc-types-annotations/.
i still, however, cannot seem find way tell ide "this" value in many jquery callbacks htmlelements. example:
/** * enable input * @returns {someconstructor} */ someconstructor.prototype.enableinput = function(){ this.$markup.find('input').each(function(){ this.disabled = false; }); return this; };
the above example still produce warning in ide - "potentially invalid usage of this".
how can specify "this" refers htmlelement object?
edit:
after looking through jsdoc documentation found @this annotation http://usejsdoc.org/tags-this.html. @this allow specify "this" value entire function, in posted example ide think it's returning htmlelement rather someconstructor.
@de1mar in comments nailed it. trick place /**@this {htmlelement} before closure. so, example:
/** * enable input * @returns {someconstructor} */ someconstructor.prototype.enableinput = function(){ this.$markup.find('input').each(/**@this {htmlelement}*/function(){ this.disabled = false; }); return this; };
or,
someconstructor.prototype.listenforcheck = function(){ this.$markup.find('input[type=checkbox]').on('click', /**@this {htmlinputelement}*/ function(){ //do }); };
should useful out there writing jquery in jetbrains ide. @del1mar!
Comments
Post a Comment