[转]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可以创建自己的对象。虽然JavaScript内部和浏览器本身的功能已十分强
大,但JavaScript还是提供了创建一个新对象的方法。使其不必像超文本标识语言那样,求于或其它多媒体工具,就能完成许多复杂的工作。
在JavaScript中创建一个新的对象是十分简单的。首先它必须定义一个对象,而后再为该对象创建一 ......
1.首先下载SyntaxHighlighter.
2.解压到SyntaxHighlighter目录中.
3.建立HTML文件:
<pre name="code" class="Ruby">
...Ruby代码...
</pre>
可以应用在pre和textarea两种HTML标签内,name为code,class为要着色的语言,现在支持C, C#, CSS, Delphi, Java, JScript, Php, Pyth ......
第一题
(function(){
return typeof arguments;
})();
//问自动执行函数会返回什么值
// 就是考Arguments对象的typeof
// 看平时用firebug多不多了……
第二题
var f = function g(){ return 23; };
typeof g();
//问最后一行的执行结果
//根据标准,命名函数表达式的函数名只对函数 ......
在对程序进行性能测试时需要考虑到不同规模以及不同算法的效率的不同
下面的网页是一个对排序算法的性能测试,规模就是数组的长度,而测试的两个函数分别是手动实现的快速排序算法和javascript内置的排序函数。
<!DOCTYPE window PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- ......