Last active
May 19, 2016 02:02
-
-
Save aisin/77030ac71847a094796f175ffdfe84d0 to your computer and use it in GitHub Desktop.
返回任意对象的类
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 该函数可以返回传递给它的任意对象的类 | |
function classof(o) { | |
if( o === "null" ) return "Null"; | |
if( o === "undefined") return "Undefined"; | |
Object.prototype.toString.call(o).slice(8,-1); | |
} | |
//或者,将 Object.prototype 替换为 {} 也是可以的 | |
function classof(o) { | |
if( o === "null" ) return "Null"; | |
if( o === "undefined") return "Undefined"; | |
{}.toString.call(o).slice(8,-1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment