Created
July 15, 2014 08:23
-
-
Save jorben/3c947e188b7360d99fd8 to your computer and use it in GitHub Desktop.
JAVASCRIPT的一些坑
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 坑一、js的基本类型有那些? | |
number string boolean object null undefined | |
typeof null //===>"object" | |
//这只能说是最初的JavaScript实现的bug,而现在标准就是这样规范的. | |
//V8曾经修正并实现过typeof null=== "null",但最终证明不可行.http://wiki.ecmascript.org/doku.php?id=harmony:typeof_null | |
// 坑二、NaN isNaN | |
isNaN('a') //===>true | |
isNaN('09') //===>false | |
//好吧,貌似字符会转型类型。 | |
//那么下面的怎么理解呢?. | |
//isNaN(null) ===>false | |
// 坑三 、parseInt | |
parseInt('08') + parseInt('02') | |
//chrome、 FF下 显示 10 | |
//IE下显示 2 | |
//原因:parseInt 第二个参数设置几进制,默认为8进制,但FF \Chrome为了配置使用习惯与常理默认设置了10进制。而ie 依然默认8进制。 | |
parseInt('8',8) //在IE FF CHROME 都是0 | |
//所以在使用这个函数的时候要注意配置 第二个参数 | |
//坑点四:valueOf (这个算是一个知识点吧) | |
o = {valueOf : function(v){return 1}}; console.log(++o) | |
//为什么结果是2呢? | |
//原因:重写了 valueOf | |
// 知识点一:类型转型: | |
string =======> number //使用 + 运算 | |
number ======> string //使用 String(23434) | |
+'2343434' | |
String(23434) //转string | |
// 知识点二: apply 与 call 区别 | |
var b = {s : 'ssss'};var a = function(){console.log(this.s + 'aaaa' + arguments[0])}; a.call(b,'bbbb'); | |
var b = {s : 'ssss'};var a = function(){console.log(this.s + 'aaaa' + arguments[0])}; a.apply(b,['bbbb','ccc']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment