Return to Snippet

Revision: 59285
at August 30, 2012 04:47 by LucasRinaldi


Initial Code
function is(type, obj) {
    var clas = Object.prototype.toString.call(obj).slice(8, -1);
    return obj !== undefined && obj !== null && clas === type;
}

is('String', 'test'); // true
is('String', new String('test')); // true

Initial URL

                                

Initial Description
'typeof' and 'instanceof' isn't a reliable method to find out the object class, so this is a function that does this in a more trustable way.

Initial Title
Checking Type of Object

Initial Tags

                                

Initial Language
JavaScript