ES6 In Depth: Arrow functions
阿新 • • 發佈:2019-01-07
Arrows
<script language="javascript">
<!--
document.bgColor = "brown"; // red
// -->
</script>
Old browsers would see two unsupported tags and a comment; only new browsers would see JS code.
To support this odd hack, the JavaScript engine in your browser treats the characters <!--
<script>
but everywhere in JS code. It even works in Node.
As it happens, this style of comment is standardized for the first time in ES6.
The arrow sequence -->
also denotes a one-line comment. Weirdly, while in HTML characters before the --> are part of the comment, in JS the rest of the line after the -->
is a comment.
It gets stranger. This arrow indicates a comment only when it appears at the start of a line. That’s because in other contexts, --> is an operator in JS, the goes to operator!
function countdown(n) {
while (n --> 0) // "n goes to zero"
alert(n);
blastoff();
}