Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript: what does /*@ @*/ mean?

Can someone explain how the beginning and end of the html5shim script works?

the script starts with /*@ and ends with @*/like this:

/*@cc_on(function(a,b){function ........ (this,document);@*/

What is the /*@ @*/ doing?

I would expect the /* */ sequence to comment out all lines in between them, but since the script executes, that cant be the case here? I'm confused.

found at:

http://html5shim.googlecode.com/svn/trunk/html5.js

like image 214
mikkelbreum Avatar asked Aug 22 '11 21:08

mikkelbreum


People also ask

What does || {} mean in JavaScript?

This is the logical OR operator in JS (and most other languages). It is defined in the spec at 11.11. As noted in the spec, expressions on either side will be evaluated first and the logical OR is left-to-right associative.

What does '$' mean in JavaScript?

Updated on July 03, 2019. The dollar sign ($) and the underscore (_) characters are JavaScript identifiers, which just means that they identify an object in the same way a name would. The objects they identify include things such as variables, functions, properties, events, and objects.

What does 1 mean in JavaScript?

-1, 0, and 1 in a comparison function are used to tell the caller how the first value should be sorted in relation to the second one. -1 means the first goes before the second. 1 means it goes after.

How are single line comments written in JavaScript?

Single line Javascript comments start with two forward slashes (//). All text after the two forward slashes until the end of a line makes up a comment, even when there are forward slashes in the commented text.


2 Answers

IE's JScript supports ‘conditional compilation’, a trick of hiding special browser-specific information in comments. The idea is that /*@...@*/ is such an unusual sequence of characters that it is safe to repurpose it to introduce this new syntax-level feature.

html5shiv uses it to create a piece of code that won't even try to run on most browsers (which, like you did, will interpret the whole thing as a commend), but which has special meaning to IE.

MS doc here. No other JS engine supports this. Typically you might favour more explicit behaviour-sniffing code instead, but if you really need to detect an IE feature that doesn't expose itself to sniffing otherwise, it can be handy.

like image 128
bobince Avatar answered Nov 02 '22 02:11

bobince


It's an IE-ism for "conditional compilation": http://www.javascriptkit.com/javatutors/conditionalcompile.shtml

like image 35
Marc B Avatar answered Nov 02 '22 01:11

Marc B