简体   繁体   English

Visual Studio中的JavaScript智能感知仅部分起作用

[英]JavaScript intellisense in Visual Studio only partially working

I'm seeing some strange behaviour with JavaScript intellisense in Visual Studio 2013 Express for Web. 我在Visual Studio 2013 Express for Web中看到JavaScript智能感知的一些奇怪行为。 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. 我遵循了所有我可以在Google上找到的建议,并且它几乎可以完美运行..但是与函数内部或外部有关的事情似乎正在影响它。 I am very new to JavaScript, so I might be missing something, but this doesn't make any sense to me: 我对JavaScript非常陌生,因此我可能会缺少一些东西,但这对我来说没有任何意义:

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 在Phaser.Game中,您具有以下代码

/**
* @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. 因为最初将其设置为null,所以我猜Visual Studio无法推断“ add”的类型,因为它只能在运行时确定。

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). 如果将add(...)定义为Phaser.Game.prototype.add = function(){...}或什至在使用this.add = function(){...的函数中,我想您会看到的以智能感知(这通常是用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. Visual Studio不够聪明,无法知道这是应该用于智能感知的add(...)的定义。

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. 在第二个示例中,将游戏作为参数传递,Visual Studio不够聪明,无法确定这将是哪种类型。 Because Javascript is weakly-typed the argument could be a Game, but could also be an integer, boolean or anything else for that matter. 因为Javascript的类型很弱,所以参数可以是Game,但也可以是整数,布尔值或其他任何形式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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