How to have WebStorm know that the properties of one object are linked to a declaration in another file?

I'm working on a project that is designed in a way where the references for certain JavaScript objects are abstracted away from the files where they are declared and then available later as properties of a special object.

For example, let's say I have the following files:

  • main.js
  • content.js

JavaScript in content.js is run in a completely different context, but variables that were defined in main.js are accessible under a special object. For example, if we have the following in main.js...

exportOptions({
    name: "John Smith"
});

This information is available in content.js by calling...

self.options.name;

How can I let WebStorm know that self.options.name in content.js is linked to name from main.js WITHOUT adding any extra executable code to either JavaScript files?

Are there any WebStorm specific commands/instructions that can be written in JavaScript comments or JSDoc which WebStorm can use to form this link?

I'm mainly interested in finding a solution because I love being able to autocomplete and automatically inspect code for errors/warnings/typos. Right now, WebStorm throws warnings when self.options.name is used, for example, because it is undefined in context.js.

Edit:

I realize that I could instead do the following in main.js, but I'm still unsure how to have WebStorm understand the connection between options in main.js and self.options in content.js without adding executable lines of JavaScript.

var options = {
    name: "John Smith";
};

exportOptions(options);
1 comment
Comment actions Permalink

works for me using @memberOf:

 

```

/**
*
* @memberOf twit#
*/
var options = {
name: "John Smith"
};

exportOptions(options);



/**
* @class
*/
var twit = function(){
var self = this;
self.options.name
}
```
0

Please sign in to leave a comment.