292 CHAPTER 6 Essential JavaScript and jQuery
All the IntelliSense suggestions have a yellow warning triangle, and a message is displayed
that states, “IntelliSense was unable to determine an accurate completion list for this expres-
sion. The provided list contains all identifiers in the file.”
To activate IntelliSense, you must set a reference to the jQuery file (not the IntelliSense file)
in every JavaScript file that requires IntelliSense. The following is an example of the default.js
file with the reference set.
/// <reference path="jquery-1.8.2.js" />
var txtInput;
var txtResult;
function initialize() {
txtInput = $('#txtInput');
txtResult = $('#txtResult');
clear();
}
function clear() {
txtInput.val('0');
txtResult.val('0');
}
This reference was added by just dragging and dropping the jquery-1.8.2.js file to the top
of the file. You can imagine that this can become a problem because you add many librar-
ies and have hundreds of JavaScript files in a project. You might also want to benefit from
IntelliSense in HTML files. To solve the problem, Microsoft has provided the ability to create
a reference list and then just add the reference list to the top of the JavaScript files. You do
so by adding a _references.js JavaScript file to your Scripts folder and then referencing that
file in your JavaScript files. Even though you need to add the reference to the _references.js
file to all your JavaScript files, when you add another library, you need to add it only to the
_references.js file.
Why do you need the special name and why does it need to be in the Scripts folder when
you need to reference the file explicitly? If you use a file called _references.js that is located
in the Scripts folder, you automatically have a reference to this file in your HTML pages,
although you still need to add the reference to your JavaScript files. The following is the con-
tents of the _references.js file.
/// <reference path="jquery-1.8.2.js" />
/// <reference path="qunit.js" />
Visual Studio automatically locates the associated IntelliSense file, if one exists with the
same name as the library, in the libraryName.intellisense.js format. In addition to using
IntelliSense files if they exist, Visual Studio looks at all referenced libraries and provides
default IntelliSense.
var txtResult;
function initialize() {
txtInput = $('#txtInput');