Object.prototype.toString.call() vs typeof

可以从下面例子找到答案:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
var toString = Object.prototype.toString;
var strLit = 'example';
var strStr = String('example')​;
var strObj = new String('example');
console.log(typeof strLit); // string
console.log(typeof strStr); // string
console.log(typeof strObj); // object
console.log(strLit instanceof String); // false
console.log(strStr instanceof String); // false
console.log(strObj instanceof String); // true
console.log(toString.call(strLit)); // [object String]
console.log(toString.call(strStr)); // [object String]
console.log(toString.call(strObj)); // [object String]