Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

[ת]Top 10 Things that JavaScript Got Wrong

to make a note that I love JavaScript. This article is only meant for some fun, and for us to be aware of some its short-comings.
1. The Name. JavaScript is NOT Java
We'll start with a fun jab at the name choice. While it was originally called Mocha, and then LiveScript, it was later changed to JavaScript. According to history, its similarities to the name Java was the result of a collaboration between Netscape and Sun, in exchange for Netscape bundling the Java runtime within their popular browser. It's also been noted that the name came, almost as a joke, due to the rivalry between LiveScript and Java for client-side scripting.
Nevertheless, it resulted in thousands of "JavaScript has nothing to do with Java" comments in forums across the web!
2. Null is an Object?
Consider this...
view plaincopy to clipboardprint?
console.log(typeof null); // object  
console.log(typeof null); // object
This makes zero sense. If null is the absence of a value, then how could its type be "object?" The simple answer is that it's flat-out an error that dates back to the first release of JavaScript - one that was even incorrectly carried over to Microsoft's JScript.
3. NaN !== NaN
NaN, as we'd expect refers to a value that is not a legal number. The problem is that NaN isn't equal to anything...including itself.
view plaincopy to clipboardprint?
console.log(NaN === NaN); // false  
console.log(NaN === NaN); // false
This should be wrong. Instead, if you want to determine if a value is indeed NaN, you can use the isNaN() function.
Update: after reading through some of the brilliant comments, particularly the ones relating to NaN being similar to infinity, it then makes perfect sense that NaN would not equal itself. But it can still be confusing. Refer to the comments for an in depth discussion on this!
4. Global Variables
The dependence upon global variables is widely considered to be far and away the wor


Ïà¹ØÎĵµ£º

»ùÓÚ¶ÔÏóµÄJavaScriptÓïÑÔ [4]

JavaScriptÓïÑÔÊÇ»ùÓÚ¶ÔÏóµÄ£¨Object-Based£©£¬¶ø²»ÊÇÃæÏò¶ÔÏóµÄ£¨object-
oriented£©¡£Ö®ËùÒÔ˵ËüÊÇÒ»ÃÅ»ùÓÚ¶ÔÏóµÄÓïÑÔ£¬Ö÷ÒªÊÇÒòΪËüûÓÐÌṩÏó³éÏ󡢼̳С¢ÖØÔصÈÓйØÃæÏò¶ÔÏóÓïÑÔµÄÐí¶à¹¦ÄÜ¡£¶øÊÇ°ÑÆäËüÓïÑÔËù´´½¨µÄ¸´
ÔÓ¶ÔÏóͳһÆðÀ´£¬´Ó¶øÐγÉÒ»¸ö·Ç³£Ç¿´óµÄ¶ÔÏóϵͳ¡£
¡¡¡¡¡¡¡¡ËäÈ»JavaScriptÓïÑÔÊÇÒ»ÃÅ»ùÓÚ¶ÔÏó ......

javascript±Ê¼Ç

¶¨Òå±äÁ¿
var test=10;
ʹÓöÔÏóÊôÐÔ
¿ÉÒÔʹÓà . ²Ù×÷·û»ñµÃÊôÐÔ,Ò²¿ÉÒÔʹÓÃÊý×éϱê»ñµÃ,±ÈÈç
for(var prop in document)
document.write(document[prop]+"<br>");
With ÉùÃ÷¶ÔÏó,Ö®ºóÔÙÓõ½¶ÔÏó¾Í²»±ØÉùÃ÷ÁË
with(document){
write("Hello World<br>±êÌâ: ");
write(title);
}
³£ÓöÔÏó ......

¡¾ÍƼö¡¿Ê®¸ö¿ªÔ´µÄJavascript¿ò¼Ü


 
ÏÂÃæÊÇÊ®¸ö×îÅ£µÄÒ²ÊÇ×îÁ÷ÐеÄJavascript¿ò¼Ü¡£ËüÃÇÍêÈ«¿ÉÒÔµ£ÈÎÄ¿Ç°ÊÀ½çÉϼ¸ºõËùÓÐһЩºÍAjax¼¼ÊõÏà¹ØµÄºÍͼÐνçÃæÏà¹ØµÄÒ»Çй¦ÄÜ¡£
jQuery
http://jquery.com/
Èç¹û½ñÌìÄ㻹²»ÖªµÀjQueryµÄ»°£¬ÄÇô×÷Ϊһ¸ö³ÌÐòÔ±Äã¿ÉÄÜÕæµÄÊÇ´Ó»ðÐÇÀ´µÄÁË¡£Õâ¿ÖÅÂÊÇAjaxÖÐÓ¦ÓÃ×î¹ãµÄ¿ò¼Ü¡£°üÀ¨ÁËÐí¶àºÜ²»´íµÄUI×é¼þ£¬×ö³öÍø ......

Javascript³£ÓÃÆÁ±Î

1 >ÆÁ±Î¹¦ÄÜÀà
1.1 ÆÁ±Î¼üÅÌËùÓмü
<script. language="javascript">
<!--
function document.onkeydown(){
  event.keyCode = 0;
  event.returnvalue = false;
}
-->
</script>
1.2 ÆÁ±ÎÊó±êÓÒ¼ü
ÔÚbody±êÇ©Àï¼ÓÉÏoncontextmenu=self.event.returnvalue=false
»òÕß
<scri ......

ÇÉÓÃjavascript»ñµÃÏÂÔصØÖ·

ͻȻ¼äÏëÈ¥ÏÂÊ×fire in the holeµÄÁåÉù£¬ÓÚÊÇÓÃsosoÕÒÁËһϣ¬½øÈëÁËÊÖ»úÀÖÔ° £¨http://download.shouji.com.cn/do/wave?html=&inputname=wave&wname=Fire+in+the+hole+&thsubmit=%E6%90%9C%E7%B4%A2£©£¬Ñ¡Ôñfire in the hole£¬µ¯³ö¸ö´°¿Ú£¬ÌáʾÈÃÊäÈëÊÖ»úºÅÂë¡£ÔÎËÀ£¬²»¾ÍÏÂÊ׸èÂ»¹²»ÈÃÖ±½ÓÏ¡£ºÇºÇ£¬·¢ÏÖÍ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ