3

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 Answer 1

5

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" />
Sign up to request clarification or add additional context in comments.

4 Comments

Perfect! It works. Can I verify something? We use Team foundation, will it also affect them?
No, it wont affect.
Well that's too bad but Thank you again
This is a visual studio user settings :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.