Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebStorm not recognizing dynamic methods

I'm currently writing an app in Object Oriented JavaScript, and I have a method which adds various functions on runtime to a function's prototype chain. The problem with this, is that when I try to use them in WebStorm i get an JSUnresolvedFunction error.

I've tried adding JSDoc to my code in the constructor and in the code itself but it still wont recognize the methods. Here is my code:

/**
 * Example class
 * @constructor
 *
 * @member {Function} OnConnect        <-- Doesn't work
 * @var {Function} OnConnect           <-- Doesn't work either
 * @typedef {Function} OnConnect       <-- You get the deal
 * @property {Function} OnConnect      <-- Same for this
 */
function MyClass() 
{
    // Add methods dynamically
    this.addMethods(["OnConnect", "OnDisconnect"]);

    // Add callback listener to 'OnConnect'
    // This is where WebStorm doesn't recognize my methods
    this.OnConnect(function() { 
        console.log('Callback fired!'); 
    });
}

/**
 * Add methods which do the same thing to the class
 * @param {Array} methods
 * @returns {void}
 */
MyClass.prototype.addMethods = function(methods) 
{
    for (var i in methods) {
        this[methods[i]] = function(callback) {
            /** Tons of re-used logic here */
        }
    }
}
like image 424
Paradoxis Avatar asked Apr 11 '26 16:04

Paradoxis


1 Answers

just remove everything except the @property

    /**
     * Example class
     * @constructor
     *
     * @property {Function} OnConnect
     */

    function MyClass() 

{
    // Add methods dynamically
    this.addMethods(["OnConnect", "OnDisconnect"]);

    // Add callback listener to 'OnConnect'
    // This is where WebStorm doesn't recognize my methods
    this.OnConnect(function() { 
        console.log('Callback fired!'); 
    });
}

/**
 * Add methods which do the same thing to the class
 * @param {Array} methods
 * @returns {void}
 */
MyClass.prototype.addMethods = function(methods) 
{
    for (var i in methods) {
        this[methods[i]] = function(callback) {
            /** Tons of re-used logic here */
        }
    }
}
like image 91
Zamboney Avatar answered Apr 13 '26 05:04

Zamboney



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!