Javascript Intellisense没有显示所有内容 [英] Javascript Intellisense not showing everything

查看:130
本文介绍了Javascript Intellisense没有显示所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要头脑风暴。我有一个Javascript库(jQuery,ExtJS等)的问题,它们与Visual Studio 2008中内置的Javascript Intellisense一起似乎不能很好地运行。它们提供了intellisense无法理解的某些实用程序辅助函数。

Brainstorming needed. I have a problem with Javascript libraries (jQuery, ExtJS etc.) that don't seem to play well along with Javascript Intellisense built in Visual Studio 2008. They provide certain utility helper functions that intellisense fails to understand.

即。 ExtJS代码

// convenience function to create namespace object placeholders
Ext.namespace("Root.Sub.Subsub");

或jQuery

// doing the same thing in jQuery
$.extend(window, {
   Root: {
      Sub: {
         Subsub: {}
      } 
   },
});

甚至(我认为你要维护这段代码)

or even (I pitty thou that shalt maintain this code)

$.extend(window, { Root: {}});
$.extend(Root, { Sub: {}});
$.extend(Root.Sub, { Subsub: {}});

这些调用的最终结果基本相同。 他们都不会在Visual Studio 2008中使 Root 名称空间对Javascript Intellisense 可见。如果我们知道intellisense如何工作,我们可能会能够克服这种情况。

The end result of these calls is basically the same. None of them would make Root namespace visible to Javascript Intellisense in Visual Studio 2008. If we would know how intellisense works under the hood we could probably be able to overcome this situation.

是否可以说服智能感知来显示/识别这些命名空间,而无需像以下那样直接编写对象:

Is it possible to convince Intellisense to display/recognise these namespaces, without writing objects directly like:

Root = {
   Sub: {
      Subsub: {}
   }
};

我承认第一个jQuery调用与此非常相似,但最好使用扩展功能防止删除/覆盖现有功能/名称空间。

I admit that the first jQuery call is quite similar to this one, but it's better to use extend functionality to prevent removing/overwriting existing functionality/namespaces.

我们应该如何使用这些实用程序使Intellisense工作的功能?

任何能够解释这个问题的头脑风暴的答案都是受欢迎的吗?

How should we use these utility functions to make Intellisense work?
Any brainstorming answer that would shed some light on this is welcome?

我发现如果在外部定义(即在不同的脚本文件中)并且你引用该文件,则会显示使用实用程序函数创建的命名空间:

I've found out that namespaces created with utility functions are shown if they are defined outside (ie. in a different script file) and you make a reference to that file like:

/// <reference path="different.script.file.js" />

在这种情况下一切都很好。但是如果你在同一个文件中调用实用程序函数,它们就不会列在intellisense下拉列表中。

In this case everything's fine. But if you call utility functions within the same file, they're not listed in intellisense drop down list.

推荐答案

解决方法



如果您在不同的脚本文件中使用它们并在您想要使用这些名称空间的文件中引用它们,这些实用程序方法实际上有效。

Workaround

These utility methods actually work if you use them in a different script file and reference it in the one you would like to use those namespaces.

File1.js (假设我们有一个自定义的jquery扩展名$ .ns()来注册新的命名空间)

File1.js (assumes we have a custom jquery extension $.ns() that registeres new namespaces)

$.ns("Project.Controls", "Project.Pages", "Project.General.Utilities");
...

File2.js

/// <reference path="File1.js" />

// use custom namespaces
Project.Controls.InfoWindow = function(){
    ...
};

我们将对自定义命名空间提供完整的智能感知支持。

in File2.js we would have complete intellisense support for custom namespaces.

我们必须在别处创建命名空间,因为我似乎无法在同一个脚本文件中使用它。

We have to create namespaces elsewhere because I can't seem to make it work within the same script file.

这篇关于Javascript Intellisense没有显示所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆