typeof
- 在使用 typeof 运算符时采用引用类型存储值会出现一个问题,无论引用的是什么类型的对象,它都返回 "object"。
ECMA 对Object.prototype.toString的解释
- Object.prototype.toString ( )
-
- When the toString method is called, the following steps are taken:
-
- If the this value is undefined, return "[object Undefined]".
- If the this value is null, return "[object Null]".
- Let O be the result of calling ToObject passing the this value as the argument.
- Let class be the value of the [[Class]] internal property of O.
- Return the String value that is the result of concatenating the three Strings "[object ", class, and "]".
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.4.2
- var oP = Object.prototype,
- toString = oP.toString;
-
- console.log(toString.call([123]));
- console.log(toString.call(‘123‘));
- console.log(toString.call({a: ‘123‘}));
- console.log(toString.call(/123/));
- console.log(toString.call(123));
- console.log(toString.call(undefined));
- console.log(toString.call(null));
typeof 和 Object.prototype.toString 的区别
原文:http://www.cnblogs.com/kongwen/p/4364987.html