yqt
10/9/2013 - 1:52 AM

check the type of an object in js

check the type of an object in js

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