Why /*@ isn't a comment in JavaScript?

2019-01-22 14:11发布

This script http://html5shiv.googlecode.com/svn/trunk/html5.js looks like a big comment, but it works. Why /*@ doesn't behave like a comment?

3条回答
forever°为你锁心
2楼-- · 2019-01-22 14:38

Here some more info and the source.

It is a comment - multiline comment. All browsers suports comments ( // or /* ... */ ) in JavaScript. But only IE checks for the @ in the comment and recognize the part of the script for the conditional compilation. This is for usage of the non-standart Microsoft features.

There is also conditional commentsMSDN in HTML, which will be removed in IE10.

查看更多
再贱就再见
3楼-- · 2019-01-22 14:52

It's a hack that uses IE's strange way of not considering /*@ a comment.

查看更多
一夜七次
4楼-- · 2019-01-22 14:58

This uses a proprietry Microsoft feature called conditional compilation. As far as non-Microsoft browsers are concerned, it is a comment (but they don't need the shiv).

查看更多
登录 后发表回答