Home > Web Front-end > JS Tutorial > Some views on JavaScript_javascript skills

Some views on JavaScript_javascript skills

WBOY
Release: 2016-05-16 18:52:16
Original
1131 people have browsed it

As we all know, a JS code that ends with a semicolon or a carriage return will run normally in the browser (at least in my IE7). I don’t know if this is a feature of the JS language or just a fault-tolerant function of the interpreter? Since the carriage return character can also be a sign of the end of a code, it is more troublesome when compressing JS. To compress all carriage returns, the program needs to know where the end of a statement is and add ";" after the end position. This is not an easy thing (maybe there is an easy way that I haven't thought of yet). In the end, I had to adopt a compromise method: retain the necessary carriage return characters and remove the ";", ",", " " and so on before and after the carriage return character separator. (How easy it would be if JS ended with ";" like C and other languages!)
During the development process, I also discovered a strange problem. As shown in the following code:

Copy code The code is as follows:

1
2
3<script> <br>4 <br>5function class1(){}; <br>6 <br>7class1.prototype.ShowMessage = function ShowMsg() <br>8{ <br>9 alert("ShowMsg Function!"); <br>10} <br>11var test = new class1(); <br>12test.ShowMessage(); <br>13</script>
14
15< ;/body>

The above code can run normally.
If you remove the "n" before line 11, the program becomes:
Copy the code The code is as follows:

1
2
3
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template