/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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]); } })();