tostring 本來是用來做字符串轉換的,不過現在流行用來做變量類型的檢查了。網頁設計這里也寫了一個函數,方便檢查變量的類型,可以用來代替 typeof
執行結果:
gettype("abc"); //string
gettype(true); //boolean
gettype(123); //number
gettype([]); //array
gettype({}); //object
gettype(function(){}); //function
gettype(new date); //date
gettype(new regexp); //regexp
gettype(math); //math
新聞熱點
疑難解答