Skip to content

Instantly share code, notes, and snippets.

@aisin
Last active May 19, 2016 02:02
Show Gist options
  • Save aisin/77030ac71847a094796f175ffdfe84d0 to your computer and use it in GitHub Desktop.
Save aisin/77030ac71847a094796f175ffdfe84d0 to your computer and use it in GitHub Desktop.
返回任意对象的类
// 该函数可以返回传递给它的任意对象的类
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