How to retain intellisense for JavaScript global variable in Visual Studio .NET 2008
I have a JavaScript wrapper that I initialize on body load and set to a global variable. Just after creating the object, I have full intellisense, but when referring to it later, from another function, the intellisense is lost. I presume this is because of dynamic typing:
var myWrapper;
function onload() {
myWrapper = new Wrapper(args);
myWrapper. //Intellisense here.
}
function whatever() {
myWrapper. //Intellisense lost.
}
I get round this by pretending to create the object again before my code, and then deleting the line:
function whatever() {
myWrapper = new Wrapper(); //Pretend to create object again.
myWrapper. //Intellisense returns!
}
Has the inference been improved in Visual Studio 2010, or is 开发者_运维百科there any way to tell JavaScript about the type of object I'm currently working on?
Unless you tell is what type it is (by using the new
keyword, it's going to have a hard time guessing what it is...
For example, consider the following
var myArray;
myArray. //intellisense has no idea this is meant to be an array
var myArray = new Array();
myArray. //intellisense knows it is a array (.pop, .push, .join etc)
so yeah, perhaps allow your object to be set (Without args as you have) and put it at the top...
var myWrapper = new Wrapper();
// now whenever myWrapper is used, intellisense
// should appear (provided it knows what Wrapper is
精彩评论