Webstorm Can't Distinguish Between Class Methods in JSDoc

I'm trying put JSDoc comments for a couple classes in my script. The issue I'm having is that two classes have the same method associated with them but take in different parameters. When I create a new instance either of the classes and call the method I would like it if WebStorm knew the difference between the classes and which parameter applies to each. Right now it gives me options for both parameters. In production my JSDoc library has dozens of duplicate methods that take a variety of parameters, so without being able to make the distinction it makes the autocomplete much less useful.

Here is some example code: http://pastebin.com/hG5mEhjx

Here the Bear and Human class both have an 'eat' method that takes in a food object, but one takes a fish key while the other takes a pasta key. Webstorm gives me both options in autocomplete but everyone knows bears don't eat pasta!



0

Your JSDoc is not correct... You get 2 classes,  Human and Bear, each with 'biomass' property,  plus 2 global eat() functions not related to classes above...

0
Avatar
Permanently deleted user

Ok, I was under the impression that using the 'this' keyword would tie the function to that specific class instead of make it a global function. Can you advise on how you might structure the JSDoc so that the functions would be local to that class?

0

Can you please attach a full working code of your example, which may be executed? Right now running it causes Uncaught TypeError: Cannot set property 'eat' of undefined, which is caused by this.prototype.eat = function(){} assignment. WebStorm also is confused by this statement.

0

请先登录再写评论。