有人能解释Visual Studio的这种行为吗;的Javascript智能感知

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

本文关键字:Javascript 感知 智能 能解释 Visual Studio      更新时间:2023-09-26

不久前,在编写Javascript继承函数时,我注意到Visual Studio中intellisense的一些非常奇怪的行为,我认为其他地方没有记录过。到目前为止,我已经在VS2008和VS2010中观察到了这一点,但据我所知,它可能可以追溯到更早的时候。

基本上,VS看起来是在执行一个函数,并使结果在智能意义上可用。

例如:

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.
}

就我而言,我无法用普通的语法检查器来计算这是怎么可能的——如果不执行"test()",VS不可能知道"firstname"或"lastname"是对象成员,因为在调用函数之前,它们不是成员。

有人能提出解释吗?

VS intellisense确实执行了代码(无论如何,都是伪执行)。

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