用于自定义javascript函数的Visual Studio Intellisense [英] Visual Studio Intellisense for Custom javascript function

查看:86
本文介绍了用于自定义javascript函数的Visual Studio Intellisense的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JavaScript中创建了一个自定义函数,以便于编码,因为它过于重复,无法一次又一次地输入这些函数。

I've create a custom functions in JavaScript for ease coding cause its too repetitive to type those function again and again.

我做的是创建了一个外部函数JavaScript并将其链接到我的 _Layout.cshtml 。我已成功调用它们没有任何问题,但我现在想要的是让这些自定义函数具有智能感知。

What I do is I created an external JavaScript and linked it to my _Layout.cshtml. I've successfully called them without any problem but what I wanted now is to have those custom function to have intellisense.

global_functions.js

function ZeroPrefixFormat(str, len) {
     str = str.toString();
     return str.length < len ? ZeroPrefixFormat("0" + str, len) : str;
     // OUTPUT : 10 -> 00010 (DIFFERS FROM THE GIVEN LENGTH)
}

function MoneyFormat(amount) {
     amount = amount.toString();
     return Number(amount).toLocaleString('en');
     // RETURN raw number to money format example. 123456789.10 -> 123,456,789.10
}

custom.cshtml

<script>
 console.log(MoneyFormat(123456789));
<script>

因此,当我尝试输入 Money 时,它会显示intellisense。

So when I try to type Money it shows intellisense.

推荐答案

您可以通过以下两种方式包含Intellisense,

You can include Intellisense in following two ways,


  1. 将JavaScript文件添加到全局Visual Studio引用

  2. 将引用直接添加到Javascript文件的顶部

将.js文件添加到全局参考

添加对的引用JS 文件在工具 - >选项这样,

确保在参考组下拉列表中选择隐式(Web)。否则它将不会对Web项目生效。

Make sure to chose Implicit (Web) in the Reference Group dropdown. Otherwise it won't take effect for web projects.

参考链接: http://madskristensen.net/post/improved- javascript-intellisense-in-visual-studio

将引用直接添加到 .js的顶部 file

Add the reference directly to the top of the .js file

您可以使用相对路径将引用直接添加到Javascript文件的顶部。

You can add the reference directly to the top of the Javascript file with the relative path as below.

/// <reference path="../scripts/jaydata.js" />

这篇关于用于自定义javascript函数的Visual Studio Intellisense的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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