Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript: Why if(false)?

I saw this in code. It blew my mind.

<% if (false) { %>
<script type="text/javascript" src="~/Scripts/jquery-1.3.2.js"></script>    
<% } %>

This seems so patently illogical that it must be intentional. I can only assume that somehow this "came up", and somebody inserted this as a work-around. There are, of course, no comments.

Why would someone do this?

like image 289
Visionary Software Solutions Avatar asked Jul 13 '10 17:07

Visionary Software Solutions


2 Answers

That's a trick to get Visual Studio to include the javascript Intellisense for jQuery without actually emitting the script to callers.

Here is an example from Scott Gu explaining it.

like image 98
Erik Forbes Avatar answered Oct 12 '22 18:10

Erik Forbes


Intellisense in Visual Studio works for jQuery if you add that to every .aspx, .ascx file.
But instead of including it in every file it is included only in the masterpage. Visual Studio parses the markup files and finds a reference to jQuery and then uses the provided intellisense on it.

You'll also need to add a vsdocs.js file into the project.
You can read more about it here.

like image 32
Sani Singh Huttunen Avatar answered Oct 12 '22 18:10

Sani Singh Huttunen