Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get VS javascript intellisense for js in a different file

So I've defined my 'enum' at the top of my javascript file as so:

var loaderOptions = { "SHOW": 0,     "CHANGEPAGE": 1,     "HIDE": 2 }; 

I wanted this enum to be used in a utility function used later ( showLoader(miliseconds, elementOrPageID, option, textMessage, callbackFunc) {} ).

This is all working fabulously as I have intellisense when I call the enum/variable enter image description here

HOWEVER, I would like to move the function and its enum OUT of my main file into a utility file ... I can make this work just fine but I lose the intellisense ... any tricks to be able to keep this ability?

like image 928
Todd Vance Avatar asked Oct 12 '12 16:10

Todd Vance


People also ask

Can JavaScript be in a separate file give details?

You can keep JavaScript code in a separate file and then include it wherever it's needed, or you can define functionality inside HTML document itself.

Can you have multiple functions in one JavaScript file?

Yes. Of course. After all, all "external functions" are really just side-effects of polluting the global ( window ) namespace in some fashion.

How do I import JavaScript into Visual Studio?

With your project open in Visual Studio, right-click on a folder or your project node in Solution Explorer (right pane), and choose Add > New Item. In the New File dialog box, under the General category, choose the file type that you want to add, such as JavaScript File, and then choose Open.


2 Answers

Add a References Directive on top of the JavaScript file

/// <reference path="file1.js" /> 

MSDN Doc

like image 90
epascarello Avatar answered Oct 05 '22 02:10

epascarello


Mads Kristensen's blog post on the _references.js file shows a more recent way of handling this than the one epascarello mentions in his answer. Here's a quote from Mads's post:

Enter _references.js.

This file must (by default) be located in a folder at the root called /scripts/. That's the naming convention. Any file located at /scripts/_references.js is automatically added to global Intellisense. This is now the only file we need for triple-slash references. Here's what the contents of this file may look like:

/// <reference path="modernizr-2.6.2.js" />  /// <reference path="jquery-1.10.2.js" />  /// <reference path="bootstrap.js" />  /// <reference path="respond.js" /> 

Just a bunch of references. This is also the only file that is included in Intellisense by default at all times.

like image 24
dumbledad Avatar answered Oct 05 '22 01:10

dumbledad