Your Ad Here

Posted By

iTony on 01/13/09


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

VaiT


Find type of variable


 / Published in: JavaScript
 

  1. function type(o){
  2. return !!o && Object.prototype.toString.call(o).match(/(\w+)\]/)[1];
  3. }
  4.  
  5. // or this way too
  6.  
  7. (function(){
  8. var types = ['Array','Function','Object','String','Number'],
  9. typesLength = types.length;
  10. while (typesLength--) {
  11. window['is' + types[typesLength]] = (function(type){
  12. return function(o) {
  13. return !!o && ( Object.prototype.toString.call(o) === '[object ' + type + ']' );
  14. }
  15. })(types[typesLength]);
  16. }
  17. })();

Report this snippet  

You need to login to post a comment.