I am currently working on an updated version of Wormbites.  In the process, I wanted to use my typeOf() function that I posted here. The only thing is, I thought it would be even better if the function would optionally take two parameters, in which case it would check to see if the first parameter was of the type specified in the second parameter. Thusly, the updated version of this function is as follows:

(function(_, g, u) {
  typeOf = function(o, p) {
    o = o === g
      ? "global"
      : o == u
        ? o === u
          ? "undefined"
          : "null"
        : _.toString.call(o).slice(8, -1);
    return p ? p === o : o;
  };
})({}, this);

The following is an example of running this function with the new parameter:

alert(typeOf(23, "Number"));  // true
alert(typeOf(23));  // Number

If the next version of jPaq ever comes out, I can guarantee that it will have this update. Have fun! 8)


Leave a Reply

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