我們可以通過constructor來判斷數據的類型,但是除了null、undefined,因爲他們不是由對象構建。
數字、布爾值、字符串是包裝類對象,所以有constructor
數字
var num = 1;
num.constructor
ƒ Number() { [native code] }
布爾值
true.constructor
ƒ Boolean() { [native code] }
字符串
"".constructor
ƒ String() { [native code] }
函數
var func = function(){}
func.constructor
ƒ Function() { [native code] }
數組
[].constructor
ƒ Array() { [native code] }
對象
var obj = {}
obj.constructor
ƒ Object() { [native code] }