IsTypeOf Function

The IsTypeOf function is design to allow you to type identify any object.


/*
/////////////////////////////////////////////////////////////////////////////////////////////////////
//  IsTypeOf                                                                             IsTypeOf  //
/////////////////////////////////////////////////////////////////////////////////////////////////////
*/
IsTypeOf=function(obj,_strict) {
  if(obj==null||obj===undefined){return null;}
  if(typeof(obj) == 'object'){
    switch(obj.constructor){
      case Array:   rtn='Array';   break;
      case Boolean: rtn='Boolean'; break;
      case Date:    rtn='Date';    break;
      case Error:   rtn='Error';   break;
      case Number:  rtn='Number';  break;
      case RegExp:  rtn='RegExp';  break;
      case String:  rtn='String';  break;
      case Object:  rtn='Object';  break;
      default:
        if(obj.constructor!==undefined){
          rtn=String(obj.constructor).substring(String(obj.constructor).search(' '), String(obj.constructor).search('{')-3);
        }else if(obj.item!==undefined){
          rtn='HTMLCollection';
        }else{
          rtn='object';
        }
    }
    return _strict===undefined||!_strict ? rtn.toLowerCase() : rtn;
  }else{
    return typeof(obj);
  }
}

Aaron Gwin

I'm developer at MasterCard focused on user experience and user interface design using Java & GXT. Web Developer, JavaScript, UX, Usability, RWD, a11y/ARIA/ADA, Java GWT/GXT, .NET, PHP. I led a patent-pending effort to create a client-side rapid html prototyping tool to demonstrate screen flows. patents US20120204102 Past positions: Business Analysts and Pega Process Architect. I love to learn.​ I'm currently learning JS Touch Events and Icon Font development.​

More Posts - Website - Twitter - LinkedIn

About Aaron Gwin

I'm developer at MasterCard focused on user experience and user interface design using Java & GXT. Web Developer, JavaScript, UX, Usability, RWD, a11y/ARIA/ADA, Java GWT/GXT, .NET, PHP. I led a patent-pending effort to create a client-side rapid html prototyping tool to demonstrate screen flows. patents US20120204102 Past positions: Business Analysts and Pega Process Architect. I love to learn.​ I'm currently learning JS Touch Events and Icon Font development.​
This entry was posted in JavaScript and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>