views:

185

answers:

6

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?

A: 

This is just like a comment, to do not execute the script.

will.i.am
That is obvious.
Visionary Software Solutions
The question is obvious not my answer
will.i.am
if (false) obviously never evaluates to true. Of course it never executes. This does work like a comment, but there's commenting syntax in the language. If I assume the code was written by Bad.Developer, this makes sense. The accepted answers, however, explain it within a context of Decent.Developer.
Visionary Software Solutions
+2  A: 

if(false) is a quick and dirty way to comment out a bunch of code

orangeoctopus
quicker than /* ... */? seems pretty bad to me.
Visionary Software Solutions
+2  A: 

is there another line of code that looks like

<script type="text/javascript" src="~/Scripts/jquery-min.1.3.2.js"></script>  

or similar? My guess is whoever wrote this wanted to have an easy way to switch in the big jQuery file for debugging purposes

Scott Evernden
Good try, though I would venture that's not a very good way of switching between jQuery versions.
Visionary Software Solutions
+1  A: 

To comment out code.

ASP does not respect HTML comments, so some people will use this, not knowing that ASP has its own syntax for comments.

Stargazer712
This does work like a comment, but there's commenting syntax in the language. If I assume the code was written by Bad.Developer, this makes sense. The accepted answers, however, explain it within a context of Decent.Developer.
Visionary Software Solutions
@Visonary Software Solutions, You are correct that the accepted answers do a better job explaining it, but I've left this answer up simply because I have (sadly) seen people do this when their intentions were to comment out code. So listen to the higher ranked answers first, but just know that it can be used in this way as well :)
Stargazer712
+8  A: 

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.

Sani Huttunen
+10  A: 

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.

Erik Forbes
Sounds right to me. I've used this sort of trick with <style> and <script> tags to get text editors to show the right highlighting for certain sections.
Alex JL