Improving the performance of my "type" function I'm writing a JavaScript library, and I am using this function for type detection:

function type(obj){
    return  Object.prototype.toString.call(obj).replace(/([\[\]]|object|\s)/gi, "");
}


Their works ok, but compared to jQuery and MooTools it stinks.

http://jsperf.com/code-type-test-a-test



How can I improve its performance?
Interesting question, since there is only 1 line to review and a limited amount of ways to get the 'type` of an object

I will say that 

function type(obj){
  return  Object.prototype.toString.call(obj).replace(/([\[\]]|object|\s)/gi, "");
}
var o = new (function Name(){})();
console.log( type(o) );


returns ""

whereas

function type(o){
  return  o !== undefined &amp;&amp; o.constructor ? o.constructor.name : "Undefined";
}
var o = new (function Name(){})();
console.log( type(o) );


returns "Name" which is more correct.

It seems ( though I fudged it a little, a re-test is required ) that the second approach can be faster on IE and Safari ). All in all, I would copy the jQuery source, it takes care of all corner cases and is sufficiently fast.