简体   繁体   中英

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. I've observed this so far in VS2008 and VS2010, but it could date back earlier for all I know.

Basically, VS appears to be executing a function and making the results available in intellisense.

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.

Can anyone suggest an explanation?

VS intellisense does indeed execute the code (pseudo-execute, anyway).

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

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