Last active
March 24, 2016 14:48
-
-
Save co3moz/2fee40916efc8ba461ac to your computer and use it in GitHub Desktop.
Small size object type checker for js
This file contains hidden or 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
var check = function(o) { | |
return (o == null) ? null : o.constructor == Function ? o.name == "" ? "Callback" : "Class_" + o.name : o.constructor.name; | |
}; | |
// how can be different check and typeof | |
// checkfor check result typeof result | |
check(null); //null "object" | |
check(undefined); //null "undefined" | |
check(1); //"Number" "number" | |
check([]); //"Array" "object" | |
check({}); //"Object" "object" | |
check(true); //"Boolean" "boolean" | |
check("yello"); //"String" "string" | |
check(function(){}); //"Callback" "function" | |
function Test() {} | |
check(Test); //"Class_Test" "function" | |
check(new Test); //"Test" "object" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example