define( [
"./core",
+ "./core/toType",
"./var/isFunction",
"./var/rnothtmlwhite"
-], function( jQuery, isFunction, rnothtmlwhite ) {
+], function( jQuery, toType, isFunction, rnothtmlwhite ) {
"use strict";
if ( !options.unique || !self.has( arg ) ) {
list.push( arg );
}
- } else if ( arg && arg.length && jQuery.type( arg ) !== "string" ) {
+ } else if ( arg && arg.length && toType( arg ) !== "string" ) {
// Inspect recursively
add( arg );
"./var/support",
"./var/isFunction",
"./var/isWindow",
- "./core/DOMEval"
+ "./core/DOMEval",
+ "./core/toType"
], function( arr, document, getProto, slice, concat, push, indexOf,
class2type, toString, hasOwn, fnToString, ObjectFunctionString,
- support, isFunction, isWindow, DOMEval ) {
+ support, isFunction, isWindow, DOMEval, toType ) {
"use strict";
return true;
},
- type: function( obj ) {
- if ( obj == null ) {
- return obj + "";
- }
-
- // Support: Android <=2.3 only (functionish RegExp)
- return typeof obj === "object" || typeof obj === "function" ?
- class2type[ toString.call( obj ) ] || "object" :
- typeof obj;
- },
-
// Evaluates a script in a global context
globalEval: function( code ) {
DOMEval( code );
// hasOwn isn't used here due to false negatives
// regarding Nodelist length in IE
var length = !!obj && "length" in obj && obj.length,
- type = jQuery.type( obj );
+ type = toType( obj );
if ( isFunction( obj ) || isWindow( obj ) ) {
return false;
define( [
"../core",
+ "../core/toType",
"../var/isFunction"
-], function( jQuery, isFunction ) {
+], function( jQuery, toType, isFunction ) {
"use strict";
bulk = key == null;
// Sets many values
- if ( jQuery.type( key ) === "object" ) {
+ if ( toType( key ) === "object" ) {
chainable = true;
for ( i in key ) {
access( elems, fn, i, key[ i ], true, emptyGet, raw );
--- /dev/null
+define( [
+ "../var/class2type",
+ "../var/toString"
+], function( class2type, toString ) {
+
+"use strict";
+
+function toType( obj ) {
+ if ( obj == null ) {
+ return obj + "";
+ }
+
+ // Support: Android <=2.3 only (functionish RegExp)
+ return typeof obj === "object" || typeof obj === "function" ?
+ class2type[ toString.call( obj ) ] || "object" :
+ typeof obj;
+}
+
+return toType;
+} );
"./core",
"./core/nodeName",
"./core/camelCase",
+ "./core/toType",
"./var/isFunction",
"./var/isWindow",
"./var/slice",
"./event/alias"
-], function( jQuery, nodeName, camelCase, isFunction, isWindow, slice ) {
+], function( jQuery, nodeName, camelCase, toType, isFunction, isWindow, slice ) {
"use strict";
jQuery.isFunction = isFunction;
jQuery.isWindow = isWindow;
jQuery.camelCase = camelCase;
+jQuery.type = toType;
jQuery.now = Date.now;
define( [
"../core",
+ "../core/toType",
"./var/rtagName",
"./var/rscriptType",
"./wrapMap",
"./getAll",
"./setGlobalEval"
-], function( jQuery, rtagName, rscriptType, wrapMap, getAll, setGlobalEval ) {
+], function( jQuery, toType, rtagName, rscriptType, wrapMap, getAll, setGlobalEval ) {
"use strict";
if ( elem || elem === 0 ) {
// Add nodes directly
- if ( jQuery.type( elem ) === "object" ) {
+ if ( toType( elem ) === "object" ) {
// Support: Android <=4.0 only, PhantomJS 1 only
// push.apply(_, arraylike) throws on ancient WebKit
define( [
"./core",
+ "./core/toType",
"./manipulation/var/rcheckableType",
"./var/isFunction",
"./core/init",
"./traversing", // filter
"./attributes/prop"
-], function( jQuery, rcheckableType, isFunction ) {
+], function( jQuery, toType, rcheckableType, isFunction ) {
"use strict";
}
} );
- } else if ( !traditional && jQuery.type( obj ) === "object" ) {
+ } else if ( !traditional && toType( obj ) === "object" ) {
// Serialize object item.
for ( name in obj ) {
dataType: "jsonp",
crossDomain: crossDomain,
success: function( data ) {
- assert.strictEqual( jQuery.type( data ), "array", "JSON results returned (GET, REST-like with param)" );
+ assert.ok( Array.isArray( data ), "JSON results returned (GET, REST-like with param)" );
}
}
];
}
QUnit.test( "core", function( assert ) {
- assert.expect( 21 );
+ assert.expect( 17 );
var elem = jQuery( "<div></div><span></span>" );
assert.strictEqual( elem.length, 2, "Correct number of elements" );
assert.strictEqual( jQuery.trim( " hello " ), "hello", "jQuery.trim" );
- assert.strictEqual( jQuery.type( null ), "null", "jQuery.type(null)" );
- assert.strictEqual( jQuery.type( undefined ), "undefined", "jQuery.type(undefined)" );
- assert.strictEqual( jQuery.type( "a" ), "string", "jQuery.type(String)" );
-
assert.ok( jQuery.isPlainObject( { "a": 2 } ), "jQuery.isPlainObject(object)" );
assert.ok( !jQuery.isPlainObject( "foo" ), "jQuery.isPlainObject(String)" );
assert.equal( jQuery.trim( "\uFEFF \xA0! | \uFEFF" ), "! |", "leading/trailing should be trimmed" );
} );
-QUnit.test( "type", function( assert ) {
- assert.expect( 28 );
-
- assert.equal( jQuery.type( null ), "null", "null" );
- assert.equal( jQuery.type( undefined ), "undefined", "undefined" );
- assert.equal( jQuery.type( true ), "boolean", "Boolean" );
- assert.equal( jQuery.type( false ), "boolean", "Boolean" );
- assert.equal( jQuery.type( Boolean( true ) ), "boolean", "Boolean" );
- assert.equal( jQuery.type( 0 ), "number", "Number" );
- assert.equal( jQuery.type( 1 ), "number", "Number" );
- assert.equal( jQuery.type( Number( 1 ) ), "number", "Number" );
- assert.equal( jQuery.type( "" ), "string", "String" );
- assert.equal( jQuery.type( "a" ), "string", "String" );
- assert.equal( jQuery.type( String( "a" ) ), "string", "String" );
- assert.equal( jQuery.type( {} ), "object", "Object" );
- assert.equal( jQuery.type( /foo/ ), "regexp", "RegExp" );
- assert.equal( jQuery.type( new RegExp( "asdf" ) ), "regexp", "RegExp" );
- assert.equal( jQuery.type( [ 1 ] ), "array", "Array" );
- assert.equal( jQuery.type( new Date() ), "date", "Date" );
- assert.equal( jQuery.type( new Function( "return;" ) ), "function", "Function" );
- assert.equal( jQuery.type( function() {} ), "function", "Function" );
- assert.equal( jQuery.type( new Error() ), "error", "Error" );
- assert.equal( jQuery.type( window ), "object", "Window" );
- assert.equal( jQuery.type( document ), "object", "Document" );
- assert.equal( jQuery.type( document.body ), "object", "Element" );
- assert.equal( jQuery.type( document.createTextNode( "foo" ) ), "object", "TextNode" );
- assert.equal( jQuery.type( document.getElementsByTagName( "*" ) ), "object", "NodeList" );
-
- // Avoid Lint complaints
- var MyString = String,
- MyNumber = Number,
- MyBoolean = Boolean,
- MyObject = Object;
- assert.equal( jQuery.type( new MyBoolean( true ) ), "boolean", "Boolean" );
- assert.equal( jQuery.type( new MyNumber( 1 ) ), "number", "Number" );
- assert.equal( jQuery.type( new MyString( "a" ) ), "string", "String" );
- assert.equal( jQuery.type( new MyObject() ), "object", "Object" );
-} );
-
-QUnit.test( "type for `Symbol`", function( assert ) {
- // Prevent reference errors
- if ( typeof Symbol !== "function" ) {
- assert.expect( 0 );
- return;
- }
-
- assert.expect( 2 );
-
- assert.equal( jQuery.type( Symbol() ), "symbol", "Symbol" );
- assert.equal( jQuery.type( Object( Symbol() ) ), "symbol", "Symbol" );
-} );
-
QUnit.asyncTest( "isPlainObject", function( assert ) {
assert.expect( 23 );
nodes = jQuery.parseHTML( jQuery( "body" )[ 0 ].innerHTML );
assert.ok( nodes.length > 4, "Parse a large html string" );
- assert.equal( jQuery.type( nodes ), "array", "parseHTML returns an array rather than a nodelist" );
+ assert.ok( Array.isArray( nodes ), "parseHTML returns an array rather than a nodelist" );
html = "<script>undefined()</script>";
assert.equal( jQuery.parseHTML( html ).length, 0, "Ignore scripts by default" );
assert.strictEqual( funcPromise, func, "non objects get extended" );
jQuery.each( promise, function( key ) {
if ( typeof promise[ key ] !== "function" ) {
- assert.ok( false, key + " is a function (" + jQuery.type( promise[ key ] ) + ")" );
+ assert.ok( false, key + " is a function (" + typeof( promise[ key ] ) + ")" );
}
if ( promise[ key ] !== func[ key ] ) {
assert.strictEqual( func[ key ], promise[ key ], key + " is the same" );
} );
-QUnit.test( "core", function( assert ) {
+QUnit.test( "type", function( assert ) {
+ assert.expect( 28 );
+
+ assert.equal( jQuery.type( null ), "null", "null" );
+ assert.equal( jQuery.type( undefined ), "undefined", "undefined" );
+ assert.equal( jQuery.type( true ), "boolean", "Boolean" );
+ assert.equal( jQuery.type( false ), "boolean", "Boolean" );
+ assert.equal( jQuery.type( Boolean( true ) ), "boolean", "Boolean" );
+ assert.equal( jQuery.type( 0 ), "number", "Number" );
+ assert.equal( jQuery.type( 1 ), "number", "Number" );
+ assert.equal( jQuery.type( Number( 1 ) ), "number", "Number" );
+ assert.equal( jQuery.type( "" ), "string", "String" );
+ assert.equal( jQuery.type( "a" ), "string", "String" );
+ assert.equal( jQuery.type( String( "a" ) ), "string", "String" );
+ assert.equal( jQuery.type( {} ), "object", "Object" );
+ assert.equal( jQuery.type( /foo/ ), "regexp", "RegExp" );
+ assert.equal( jQuery.type( new RegExp( "asdf" ) ), "regexp", "RegExp" );
+ assert.equal( jQuery.type( [ 1 ] ), "array", "Array" );
+ assert.equal( jQuery.type( new Date() ), "date", "Date" );
+ assert.equal( jQuery.type( new Function( "return;" ) ), "function", "Function" );
+ assert.equal( jQuery.type( function() {} ), "function", "Function" );
+ assert.equal( jQuery.type( new Error() ), "error", "Error" );
+ assert.equal( jQuery.type( window ), "object", "Window" );
+ assert.equal( jQuery.type( document ), "object", "Document" );
+ assert.equal( jQuery.type( document.body ), "object", "Element" );
+ assert.equal( jQuery.type( document.createTextNode( "foo" ) ), "object", "TextNode" );
+ assert.equal( jQuery.type( document.getElementsByTagName( "*" ) ), "object", "NodeList" );
+
+ // Avoid Lint complaints
+ var MyString = String,
+ MyNumber = Number,
+ MyBoolean = Boolean,
+ MyObject = Object;
+ assert.equal( jQuery.type( new MyBoolean( true ) ), "boolean", "Boolean" );
+ assert.equal( jQuery.type( new MyNumber( 1 ) ), "number", "Number" );
+ assert.equal( jQuery.type( new MyString( "a" ) ), "string", "String" );
+ assert.equal( jQuery.type( new MyObject() ), "object", "Object" );
+} );
+
+QUnit[ typeof Symbol === "function" ? "test" : "skip" ]( "type for `Symbol`", function( assert ) {
assert.expect( 2 );
- assert.ok( jQuery.isFunction( jQuery.noop ), "jQuery.isFunction(jQuery.noop)" );
- assert.ok( !jQuery.isFunction( 2 ), "jQuery.isFunction(Number)" );
+ assert.equal( jQuery.type( Symbol() ), "symbol", "Symbol" );
+ assert.equal( jQuery.type( Object( Symbol() ) ), "symbol", "Symbol" );
} );
-
QUnit.test( "isFunction", function( assert ) {
assert.expect( 20 );