Skip to content

Commit

Permalink
Moving type check vars outside of typeOf definition to speed up subse…
Browse files Browse the repository at this point in the history
…quent lookups.
  • Loading branch information
Irene Ros committed Nov 30, 2011
1 parent 2c4bcf3 commit e67d4bb
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/ds.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,23 +459,26 @@
});


/**
* Returns the type of an input object.
* Stolen from jQuery via @rwaldron (http://pastie.org/2849690)
* @param {?} obj - the object being detected.
*/
DS.typeOf = function(obj) {
(function() {
var classType = {},
types = "Boolean Number String Function Array Date RegExp Object".split(" "),
length = types.length,
i = 0;
for ( ; i < length; i++ ) {
classType[ "[object " + types[ i ] + "]" ] = types[ i ].toLowerCase();
}
return obj == null ?
String( obj ) :
classType[ {}.toString.call(obj) ] || "object";
};
/**
* Returns the type of an input object.
* Stolen from jQuery via @rwaldron (http://pastie.org/2849690)
* @param {?} obj - the object being detected.
*/
DS.typeOf = function(obj) {

return obj == null ?
String( obj ) :
classType[ {}.toString.call(obj) ] || "object";
};
})();

DS.VERSION = "0.0.1";

Expand Down

0 comments on commit e67d4bb

Please sign in to comment.