简体   繁体   English

谁能解释Visual Studio Javascript智能感知的这种行为?

[英]Can anyone explain this behaviour of Visual Studio's Javascript intellisense?

While writing a Javascript inheritance function some time ago I noticed some very strange behaviour with intellisense in Visual Studio, that I don't think has been documented elsewhere. 前段时间编写Javascript继承函数时,我注意到Visual Studio中的intellisense有一些非常奇怪的行为,我认为没有其他地方对此进行了记录。 I've observed this so far in VS2008 and VS2010, but it could date back earlier for all I know. 到目前为止,我已经在VS2008和VS2010中观察到了这一点,但据我所知,它可以追溯到更早。

Basically, VS appears to be executing a function and making the results available in intellisense. 基本上,VS似乎正在执行一个功能并使结果可在智能感知中使用。

For example: 例如:

function test(obj, member, value) {
    obj[member] = value;
    return obj;
}

function harness() {
    var obj = {};
    test(obj, "firstname", "Jack");
    test(obj, "lastname", "Bauer");
    // If you now type in 'obj.' and wait for intellisense to pop-up you will notice that 'firstname' and 'lastname' will appear as members.
}

For the life of me I can't work out how this is possible with a normal syntax checker -- VS could not possibly know that 'firstname' or 'lastname' was an object member without executing 'test()' as they aren't members until the function is called. 在我的一生中,我无法弄清楚使用常规语法检查器如何做到这一点-VS在不执行“ test()”的情况下无法知道“名字”或“姓氏”是对象成员吗? t个成员,直到调用该函数。

Can anyone suggest an explanation? 有人可以提出解释吗?

VS intellisense does indeed execute the code (pseudo-execute, anyway). VS intellisense确实确实执行了代码(无论如何都是伪执行)。

Take a look at this: http://weblogs.asp.net/scottgu/archive/2010/04/08/javascript-intellisense-improvements-with-vs-2010.aspx 看看这个: http : //weblogs.asp.net/scottgu/archive/2010/04/08/javascript-intellisense-improvements-with-vs-2010.aspx

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

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