使用Visual Studio模拟铸造';s JavaScript智能感知

使用Visual Studio模拟铸造';s JavaScript智能感知,javascript,visual-studio,visual-studio-2010,intellisense,Javascript,Visual Studio,Visual Studio 2010,Intellisense,我通过如下数组将jQuery对象从另一个文件传递到函数中: $(document).bind("loadStoreDisplayCallGoals", function(source, urlParams) { var selectedStoreDocument = urlParams["storeDocument"]; } selectedStoreDocument应该是jQuery对象,但是Visual Studio Intellisense永远不会识别它。我尝试使用$添加扩展se

我通过如下数组将jQuery对象从另一个文件传递到函数中:

$(document).bind("loadStoreDisplayCallGoals", function(source, urlParams)
{
    var selectedStoreDocument = urlParams["storeDocument"];
}
selectedStoreDocument
应该是jQuery对象,但是Visual Studio Intellisense永远不会识别它。我尝试使用
$添加扩展
selectedStoreDocument
。扩展

// cast selectedStoreDocument to a jQuery type
$.extend(selectedStoreDocument, $);
但是,扩展
selectedStoreDocument
删除了我所有的jQuery方法(
.each
.find
,等等)


如何使
selectedStoreDocument
在IntelliSense中显示为jQuery对象?请注意,我在Visual Studio 2010中工作。

您无法获取动态添加属性的intellisense。您需要静态地定义它们(在vsdoc或js文件中):

$。selectedStoreDocument=函数(){
///选定的存储文档
};

我为实用程序函数创建了一个单独的文件,为实用程序函数+VSDoc创建了第二个文件

utilities.js:

function castToJQuery(item)
{
    return item;
}
utilities-vsdoc.js:

function castToJQuery(item)
{
    /// <summary>
    ///     1: $(item) - "Casts" the specified item to a jQuery object for the sake of Intellisense
    /// </summary>
    /// <returns type="jQuery" />
    return $("dummy");
}

Visual Studio现在可与Intellisense一起用于my dynamic urlParams[“storeDocument”]。

您可以为以下变量指定文档信息:

$(document).bind("loadStoreDisplayCallGoals", function(source, urlParams)
{
    /// <var type="jQuery"/>
    var selectedStoreDocument = urlParams["storeDocument"];
    selectedStoreDocument._
}
$(document).bind(“loadStoreDisplayCallGoals”,函数(源,urlParams)
{
/// 
var selectedStoreDocument=urlParams[“storeDocument”];
选择存储文档_
}

有关更多信息,请参见

,因此无法“强制转换”关于intellisense的东西?Javascript不是编译语言,VS也没有可以评估语言并为您提供类似c#的intellisense的语言服务提供商。@Pedar,您应该试试ReSharper 6,它的Javascript引擎比用于intellisense(和重构等)的stock VS工具健壮得多不,我理解。我只是不确定是否有注释标记可用于类似于///我可以用来“强制转换”的选定存储文档的变量我的变量。不确定您所说的cast是什么意思。这里是对可用标记的引用:。您是否正在寻找
参数类型
?有趣的方法。您能发布一个屏幕截图吗?今天晚些时候我将尝试添加一些屏幕截图
var selectedStoreDocument = castToJQuery(urlParams["storeDocument"]);
selectedStoreDocument.find("products");
$(document).bind("loadStoreDisplayCallGoals", function(source, urlParams)
{
    /// <var type="jQuery"/>
    var selectedStoreDocument = urlParams["storeDocument"];
    selectedStoreDocument._
}