push = Array.prototype.push,
slice = Array.prototype.slice,
trim = String.prototype.trim,
- indexOf = Array.prototype.indexOf;
+ indexOf = Array.prototype.indexOf,
+
+ // [[Class]] -> type pairs
+ class2type = {};
jQuery.fn = jQuery.prototype = {
init: function( selector, context ) {
type: function( obj ) {
return obj == null ?
String( obj ) :
- toString.call(obj).slice(8, -1).toLowerCase();
+ class2type[ toString.call(obj) ] || "object";
},
isPlainObject: function( obj ) {
browser: {}
});
+// Populate the class2type map
+jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) {
+ class2type[ "[object " + name + "]" ] = name.toLowerCase();
+});
+
browserMatch = jQuery.uaMatch( userAgent );
if ( browserMatch.browser ) {
jQuery.browser[ browserMatch.browser ] = true;
});
test("type", function() {
- expect(18);
+ expect(22);
equals( jQuery.type(null), "null", "null" );
equals( jQuery.type(undefined), "undefined", "undefined" );
equals( jQuery.type(new Date()), "date", "Date" );
equals( jQuery.type(new Function("return;")), "function", "Function" );
equals( jQuery.type(function(){}), "function", "Function" );
+ equals( jQuery.type(window), "object", "Window" );
+ equals( jQuery.type(document.body), "object", "Element" );
+ equals( jQuery.type(document.createTextNode("foo")), "object", "TextNode" );
+ equals( jQuery.type(document.getElementsByTagName("*")), "object", "NodeList" );
});
test("isPlainObject", function() {