Visual Studio Intellisense for Custom javascript function

末鹿安然 提交于 2019-12-10 10:05:11

问题


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

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>

So when I try to type Money it shows intellisense.


回答1:


You can include Intellisense in following two ways,

  1. Add a JavaScript file to the global Visual Studio references
  2. Add the reference directly to the top of the Javascript file

Add a .js file to the global references

Add a reference to the JS file in Tools -> Options like this,

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

Reference Link: http://madskristensen.net/post/improved-javascript-intellisense-in-visual-studio

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

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

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


来源:https://stackoverflow.com/questions/41233715/visual-studio-intellisense-for-custom-javascript-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!