Return to Snippet

Revision: 10754
at January 13, 2009 01:12 by iTony


Initial Code
function type(o){
    return !!o && Object.prototype.toString.call(o).match(/(\w+)\]/)[1];
}

// or this way too

(function(){
    var types = ['Array','Function','Object','String','Number'],
        typesLength = types.length;
    while (typesLength--) {
        window['is' + types[typesLength]] = (function(type){
            return function(o) {
                return !!o && ( Object.prototype.toString.call(o) === '[object ' + type + ']' );
            }
        })(types[typesLength]);
    }
})();

Initial URL


Initial Description


Initial Title
Find type of variable

Initial Tags


Initial Language
JavaScript