2016-03-14 2 views
2

В настоящее время я пишу приложение в объектно-ориентированном JavaScript, и у меня есть метод, который добавляет различные функции во время выполнения в цепочку прототипов функции. Проблема с этим заключается в том, что когда я пытаюсь использовать их в WebStorm, я получаю ошибку JSUnresolvedFunction.WebStorm не распознает динамические методы

Я попытался добавить JSDoc в свой код в конструкторе и в самом коде, но он все равно не распознает методы. Вот мой код:

/** 
* 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 */ 
     } 
    } 
} 

ответ

2

просто удалить все, кроме @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 */ 
     } 
    } 
} 
Смежные вопросы