Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Intellisense for Custom javascript function

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.

like image 746
Yuu Avatar asked Apr 28 '26 04:04

Yuu


1 Answers

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.

enter image description here

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" />
like image 142
Aruna Avatar answered Apr 30 '26 18:04

Aruna



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!