/ Published in: JavaScript
'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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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