leohxj
5/28/2014 - 2:42 AM

typeof运算符和Object.prototype.toString

typeof运算符和Object.prototype.toString

typeof {foo: 'bar'};
// "object"

typeof ['foo', 'bar'];
// "object"

typeof "foobar";
// "string"

typeof /foo|bar/;
// "object"


Object.prototype.toString.call({foo: 'bar'});
// "[object Object]"

Object.prototype.toString.call(['foo', 'bar']);
// "[object Array]"

Object.prototype.toString.call("foobar");
// "[object String]"

Object.prototype.toString.call(/foo|bar/);
// "[object RegExp]"