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".

enter image description here 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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -