简体   繁体   中英

JavaScript intellisense in Visual Studio only partially working

I'm seeing some strange behaviour with JavaScript intellisense in Visual Studio 2013 Express for Web. I followed all the advice I could google, and it's almost working perfectly.. but something to do with being inside or outside of a function seems to be affecting it. I am very new to JavaScript, so I might be missing something, but this doesn't make any sense to me:

Outside of a function it seems to work partially... 在此处输入图片说明 (I get one level of intellisense)

在此处输入图片说明 (but not two)

But inside of a function it works perfectly... 在此处输入图片说明 (I get all intellisense)

In a separate file, I get a similar problem, but down one function level... 在此处输入图片说明 (limited here)

在此处输入图片说明 (but everything here)

Any advice would be much appreciated!

OK I've looked through the code here's what I think.

Within Phaser.Game you have this code

/**
* @property {Phaser.GameObjectFactory} add - Reference to the Phaser.GameObjectFactory.
*/
this.add = null;

Because this is initially set to null I'm guessing Visual Studio will not be able to infer what type "add" will be since it is only determined at run time.

If add(...) was defined as Phaser.Game.prototype.add = function() { ... } or even within the function using this.add = function() { ... } I think you would see it in intellisense (this is normally how classes are built in Javascript). However I notice you are defining it dynamically later in the code like this from a factory:

this.add = new Phaser.GameObjectFactory(this);

Visual Studio isn't smart enough to know this is the definition of add(...) it should use for intellisense.

In the second example game is passed as an argument, and visual studio is not smart enough to work out what type this will be. Because Javascript is weakly-typed the argument could be a Game, but could also be an integer, boolean or anything else for that matter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM