Java script resolution of function calls

Hello,

For example, consider the code below:

 
function hello1() {
    console.log("hello1");
}
var lib2 = function(context) {
    context.hello2 = function() {
        console.log("hello2");
    
};
};
var lib3 = function
(context) {
    context.hello3 = function() {
        console.log("hello3");
    
};
};

function main
() {
    var importedLib = {};
    lib2
(importedLib);
    lib3
(this);

    hello1
();             // resolved
    
importedLib.hello2(); // resolved
    
hello3();             // not resolved
}


For "hello1()" and "hello2()" IntelliJ will find their usages. However, calling "hello3()" without specifying "this" or some other object is not resolved.

Is there a way to fix this?


Thank you,
Dmitry

2 comments
Comment actions Permalink

Hello Dmitry,

WebStorm can't handle such dynamic bindings, but as a workaround you can use @name tag. This way hello3 will be resolved both from global context and after qualifier:

 
var lib3 = function(context) {
    /** @name hello3 */
    
context.hello3 = function() {
        console.log("hello3");
    };
};
0
Comment actions Permalink

Thank you. This does help with resolution from function invocation.

However, the function call is still not searchable from its declaration:

 
var lib3 = function(context) {
    /** @name hello3 */
    
context.hello3 = function() { // search finds only "this.hello3()"
        
console.log("hello3");    // search from string literal finds all three usages
    
};
};

function main
() {
    lib3(this);
    this
.hello3(); // search finds all three usages
    
hello3();      // search finds all three usages
}
0

Please sign in to leave a comment.