mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Core: deprecate jQuery.isFunction
Fixes gh-3609
This commit is contained in:
parent
6c38ebbd47
commit
3d732cca6b
@ -1,6 +1,7 @@
|
|||||||
define( [
|
define( [
|
||||||
"./core",
|
"./core",
|
||||||
"./var/document",
|
"./var/document",
|
||||||
|
"./var/isFunction",
|
||||||
"./var/rnothtmlwhite",
|
"./var/rnothtmlwhite",
|
||||||
"./ajax/var/location",
|
"./ajax/var/location",
|
||||||
"./ajax/var/nonce",
|
"./ajax/var/nonce",
|
||||||
@ -11,7 +12,7 @@ define( [
|
|||||||
"./event/trigger",
|
"./event/trigger",
|
||||||
"./deferred",
|
"./deferred",
|
||||||
"./serialize" // jQuery.param
|
"./serialize" // jQuery.param
|
||||||
], function( jQuery, document, rnothtmlwhite, location, nonce, rquery ) {
|
], function( jQuery, document, isFunction, rnothtmlwhite, location, nonce, rquery ) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -66,7 +67,7 @@ function addToPrefiltersOrTransports( structure ) {
|
|||||||
i = 0,
|
i = 0,
|
||||||
dataTypes = dataTypeExpression.toLowerCase().match( rnothtmlwhite ) || [];
|
dataTypes = dataTypeExpression.toLowerCase().match( rnothtmlwhite ) || [];
|
||||||
|
|
||||||
if ( jQuery.isFunction( func ) ) {
|
if ( isFunction( func ) ) {
|
||||||
|
|
||||||
// For each dataType in the dataTypeExpression
|
// For each dataType in the dataTypeExpression
|
||||||
while ( ( dataType = dataTypes[ i++ ] ) ) {
|
while ( ( dataType = dataTypes[ i++ ] ) ) {
|
||||||
@ -834,7 +835,7 @@ jQuery.each( [ "get", "post" ], function( i, method ) {
|
|||||||
jQuery[ method ] = function( url, data, callback, type ) {
|
jQuery[ method ] = function( url, data, callback, type ) {
|
||||||
|
|
||||||
// Shift arguments if data argument was omitted
|
// Shift arguments if data argument was omitted
|
||||||
if ( jQuery.isFunction( data ) ) {
|
if ( isFunction( data ) ) {
|
||||||
type = type || callback;
|
type = type || callback;
|
||||||
callback = data;
|
callback = data;
|
||||||
data = undefined;
|
data = undefined;
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
define( [
|
define( [
|
||||||
"../core",
|
"../core",
|
||||||
|
"../var/isFunction",
|
||||||
"./var/nonce",
|
"./var/nonce",
|
||||||
"./var/rquery",
|
"./var/rquery",
|
||||||
"../ajax"
|
"../ajax"
|
||||||
], function( jQuery, nonce, rquery ) {
|
], function( jQuery, isFunction, nonce, rquery ) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -36,7 +37,7 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
|
|||||||
if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) {
|
if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) {
|
||||||
|
|
||||||
// Get callback name, remembering preexisting value associated with it
|
// Get callback name, remembering preexisting value associated with it
|
||||||
callbackName = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ?
|
callbackName = s.jsonpCallback = isFunction( s.jsonpCallback ) ?
|
||||||
s.jsonpCallback() :
|
s.jsonpCallback() :
|
||||||
s.jsonpCallback;
|
s.jsonpCallback;
|
||||||
|
|
||||||
@ -87,7 +88,7 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Call if it was a function and we have a response
|
// Call if it was a function and we have a response
|
||||||
if ( responseContainer && jQuery.isFunction( overwritten ) ) {
|
if ( responseContainer && isFunction( overwritten ) ) {
|
||||||
overwritten( responseContainer[ 0 ] );
|
overwritten( responseContainer[ 0 ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
define( [
|
define( [
|
||||||
"../core",
|
"../core",
|
||||||
"../core/stripAndCollapse",
|
"../core/stripAndCollapse",
|
||||||
|
"../var/isFunction",
|
||||||
"../core/parseHTML",
|
"../core/parseHTML",
|
||||||
"../ajax",
|
"../ajax",
|
||||||
"../traversing",
|
"../traversing",
|
||||||
"../manipulation",
|
"../manipulation",
|
||||||
"../selector"
|
"../selector"
|
||||||
], function( jQuery, stripAndCollapse ) {
|
], function( jQuery, stripAndCollapse, isFunction ) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -24,7 +25,7 @@ jQuery.fn.load = function( url, params, callback ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If it's a function
|
// If it's a function
|
||||||
if ( jQuery.isFunction( params ) ) {
|
if ( isFunction( params ) ) {
|
||||||
|
|
||||||
// We assume that it's the callback
|
// We assume that it's the callback
|
||||||
callback = params;
|
callback = params;
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
define( [
|
define( [
|
||||||
"../core",
|
"../core",
|
||||||
"../core/stripAndCollapse",
|
"../core/stripAndCollapse",
|
||||||
|
"../var/isFunction",
|
||||||
"../var/rnothtmlwhite",
|
"../var/rnothtmlwhite",
|
||||||
"../data/var/dataPriv",
|
"../data/var/dataPriv",
|
||||||
"../core/init"
|
"../core/init"
|
||||||
], function( jQuery, stripAndCollapse, rnothtmlwhite, dataPriv ) {
|
], function( jQuery, stripAndCollapse, isFunction, rnothtmlwhite, dataPriv ) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -27,7 +28,7 @@ jQuery.fn.extend( {
|
|||||||
var classes, elem, cur, curValue, clazz, j, finalValue,
|
var classes, elem, cur, curValue, clazz, j, finalValue,
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
if ( jQuery.isFunction( value ) ) {
|
if ( isFunction( value ) ) {
|
||||||
return this.each( function( j ) {
|
return this.each( function( j ) {
|
||||||
jQuery( this ).addClass( value.call( this, j, getClass( this ) ) );
|
jQuery( this ).addClass( value.call( this, j, getClass( this ) ) );
|
||||||
} );
|
} );
|
||||||
@ -64,7 +65,7 @@ jQuery.fn.extend( {
|
|||||||
var classes, elem, cur, curValue, clazz, j, finalValue,
|
var classes, elem, cur, curValue, clazz, j, finalValue,
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
if ( jQuery.isFunction( value ) ) {
|
if ( isFunction( value ) ) {
|
||||||
return this.each( function( j ) {
|
return this.each( function( j ) {
|
||||||
jQuery( this ).removeClass( value.call( this, j, getClass( this ) ) );
|
jQuery( this ).removeClass( value.call( this, j, getClass( this ) ) );
|
||||||
} );
|
} );
|
||||||
@ -113,7 +114,7 @@ jQuery.fn.extend( {
|
|||||||
return stateVal ? this.addClass( value ) : this.removeClass( value );
|
return stateVal ? this.addClass( value ) : this.removeClass( value );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( jQuery.isFunction( value ) ) {
|
if ( isFunction( value ) ) {
|
||||||
return this.each( function( i ) {
|
return this.each( function( i ) {
|
||||||
jQuery( this ).toggleClass(
|
jQuery( this ).toggleClass(
|
||||||
value.call( this, i, getClass( this ), stateVal ),
|
value.call( this, i, getClass( this ), stateVal ),
|
||||||
|
@ -3,9 +3,10 @@ define( [
|
|||||||
"../core/stripAndCollapse",
|
"../core/stripAndCollapse",
|
||||||
"./support",
|
"./support",
|
||||||
"../core/nodeName",
|
"../core/nodeName",
|
||||||
|
"../var/isFunction",
|
||||||
|
|
||||||
"../core/init"
|
"../core/init"
|
||||||
], function( jQuery, stripAndCollapse, support, nodeName ) {
|
], function( jQuery, stripAndCollapse, support, nodeName, isFunction ) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -13,7 +14,7 @@ var rreturn = /\r/g;
|
|||||||
|
|
||||||
jQuery.fn.extend( {
|
jQuery.fn.extend( {
|
||||||
val: function( value ) {
|
val: function( value ) {
|
||||||
var hooks, ret, isFunction,
|
var hooks, ret, valueIsFunction,
|
||||||
elem = this[ 0 ];
|
elem = this[ 0 ];
|
||||||
|
|
||||||
if ( !arguments.length ) {
|
if ( !arguments.length ) {
|
||||||
@ -42,7 +43,7 @@ jQuery.fn.extend( {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
isFunction = jQuery.isFunction( value );
|
valueIsFunction = isFunction( value );
|
||||||
|
|
||||||
return this.each( function( i ) {
|
return this.each( function( i ) {
|
||||||
var val;
|
var val;
|
||||||
@ -51,7 +52,7 @@ jQuery.fn.extend( {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isFunction ) {
|
if ( valueIsFunction ) {
|
||||||
val = value.call( this, i, jQuery( this ).val() );
|
val = value.call( this, i, jQuery( this ).val() );
|
||||||
} else {
|
} else {
|
||||||
val = value;
|
val = value;
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
define( [
|
define( [
|
||||||
"./core",
|
"./core",
|
||||||
|
"./var/isFunction",
|
||||||
"./var/rnothtmlwhite"
|
"./var/rnothtmlwhite"
|
||||||
], function( jQuery, rnothtmlwhite ) {
|
], function( jQuery, isFunction, rnothtmlwhite ) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -125,7 +126,7 @@ jQuery.Callbacks = function( options ) {
|
|||||||
|
|
||||||
( function add( args ) {
|
( function add( args ) {
|
||||||
jQuery.each( args, function( _, arg ) {
|
jQuery.each( args, function( _, arg ) {
|
||||||
if ( jQuery.isFunction( arg ) ) {
|
if ( isFunction( arg ) ) {
|
||||||
if ( !options.unique || !self.has( arg ) ) {
|
if ( !options.unique || !self.has( arg ) ) {
|
||||||
list.push( arg );
|
list.push( arg );
|
||||||
}
|
}
|
||||||
|
16
src/core.js
16
src/core.js
@ -16,11 +16,12 @@ define( [
|
|||||||
"./var/fnToString",
|
"./var/fnToString",
|
||||||
"./var/ObjectFunctionString",
|
"./var/ObjectFunctionString",
|
||||||
"./var/support",
|
"./var/support",
|
||||||
|
"./var/isFunction",
|
||||||
"./var/isWindow",
|
"./var/isWindow",
|
||||||
"./core/DOMEval"
|
"./core/DOMEval"
|
||||||
], function( arr, document, getProto, slice, concat, push, indexOf,
|
], function( arr, document, getProto, slice, concat, push, indexOf,
|
||||||
class2type, toString, hasOwn, fnToString, ObjectFunctionString,
|
class2type, toString, hasOwn, fnToString, ObjectFunctionString,
|
||||||
support, isWindow, DOMEval ) {
|
support, isFunction, isWindow, DOMEval ) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -137,7 +138,7 @@ jQuery.extend = jQuery.fn.extend = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle case when target is a string or something (possible in deep copy)
|
// Handle case when target is a string or something (possible in deep copy)
|
||||||
if ( typeof target !== "object" && !jQuery.isFunction( target ) ) {
|
if ( typeof target !== "object" && !isFunction( target ) ) {
|
||||||
target = {};
|
target = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,15 +204,6 @@ jQuery.extend( {
|
|||||||
|
|
||||||
noop: function() {},
|
noop: function() {},
|
||||||
|
|
||||||
isFunction: function( obj ) {
|
|
||||||
|
|
||||||
// Support: Chrome <=57, Firefox <=52
|
|
||||||
// In some browsers, typeof returns "function" for HTML <object> elements
|
|
||||||
// (i.e., `typeof document.createElement( "object" ) === "function"`).
|
|
||||||
// We don't want to classify *any* DOM node as a function.
|
|
||||||
return typeof obj === "function" && typeof obj.nodeType !== "number";
|
|
||||||
},
|
|
||||||
|
|
||||||
isNumeric: function( obj ) {
|
isNumeric: function( obj ) {
|
||||||
|
|
||||||
// As of jQuery 3.0, isNumeric is limited to
|
// As of jQuery 3.0, isNumeric is limited to
|
||||||
@ -419,7 +411,7 @@ function isArrayLike( obj ) {
|
|||||||
var length = !!obj && "length" in obj && obj.length,
|
var length = !!obj && "length" in obj && obj.length,
|
||||||
type = jQuery.type( obj );
|
type = jQuery.type( obj );
|
||||||
|
|
||||||
if ( jQuery.isFunction( obj ) || isWindow( obj ) ) {
|
if ( isFunction( obj ) || isWindow( obj ) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
define( [
|
define( [
|
||||||
"../core"
|
"../core",
|
||||||
], function( jQuery ) {
|
"../var/isFunction"
|
||||||
|
], function( jQuery, isFunction ) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -22,7 +23,7 @@ var access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
|
|||||||
} else if ( value !== undefined ) {
|
} else if ( value !== undefined ) {
|
||||||
chainable = true;
|
chainable = true;
|
||||||
|
|
||||||
if ( !jQuery.isFunction( value ) ) {
|
if ( !isFunction( value ) ) {
|
||||||
raw = true;
|
raw = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,10 +2,11 @@
|
|||||||
define( [
|
define( [
|
||||||
"../core",
|
"../core",
|
||||||
"../var/document",
|
"../var/document",
|
||||||
|
"../var/isFunction",
|
||||||
"./var/rsingleTag",
|
"./var/rsingleTag",
|
||||||
|
|
||||||
"../traversing/findFilter"
|
"../traversing/findFilter"
|
||||||
], function( jQuery, document, rsingleTag ) {
|
], function( jQuery, document, isFunction, rsingleTag ) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -63,7 +64,7 @@ var rootjQuery,
|
|||||||
for ( match in context ) {
|
for ( match in context ) {
|
||||||
|
|
||||||
// Properties of context are called as methods if possible
|
// Properties of context are called as methods if possible
|
||||||
if ( jQuery.isFunction( this[ match ] ) ) {
|
if ( isFunction( this[ match ] ) ) {
|
||||||
this[ match ]( context[ match ] );
|
this[ match ]( context[ match ] );
|
||||||
|
|
||||||
// ...and otherwise set as attributes
|
// ...and otherwise set as attributes
|
||||||
@ -106,7 +107,7 @@ var rootjQuery,
|
|||||||
|
|
||||||
// HANDLE: $(function)
|
// HANDLE: $(function)
|
||||||
// Shortcut for document ready
|
// Shortcut for document ready
|
||||||
} else if ( jQuery.isFunction( selector ) ) {
|
} else if ( isFunction( selector ) ) {
|
||||||
return root.ready !== undefined ?
|
return root.ready !== undefined ?
|
||||||
root.ready( selector ) :
|
root.ready( selector ) :
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
define( [
|
define( [
|
||||||
"../core",
|
"../core",
|
||||||
"../var/document"
|
"../var/document",
|
||||||
], function( jQuery, document ) {
|
"../var/isFunction"
|
||||||
|
], function( jQuery, document, isFunction ) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -52,7 +53,7 @@ jQuery.extend( {
|
|||||||
|
|
||||||
while ( readyCallbacks.length ) {
|
while ( readyCallbacks.length ) {
|
||||||
fn = readyCallbacks.shift();
|
fn = readyCallbacks.shift();
|
||||||
if ( jQuery.isFunction( fn ) ) {
|
if ( isFunction( fn ) ) {
|
||||||
executeReady( fn );
|
executeReady( fn );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
define( [
|
define( [
|
||||||
"./core",
|
"./core",
|
||||||
|
"./var/isFunction",
|
||||||
"./var/slice",
|
"./var/slice",
|
||||||
"./callbacks"
|
"./callbacks"
|
||||||
], function( jQuery, slice ) {
|
], function( jQuery, isFunction, slice ) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -19,11 +20,11 @@ function adoptValue( value, resolve, reject, noValue ) {
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
// Check for promise aspect first to privilege synchronous behavior
|
// Check for promise aspect first to privilege synchronous behavior
|
||||||
if ( value && jQuery.isFunction( ( method = value.promise ) ) ) {
|
if ( value && isFunction( ( method = value.promise ) ) ) {
|
||||||
method.call( value ).done( resolve ).fail( reject );
|
method.call( value ).done( resolve ).fail( reject );
|
||||||
|
|
||||||
// Other thenables
|
// Other thenables
|
||||||
} else if ( value && jQuery.isFunction( ( method = value.then ) ) ) {
|
} else if ( value && isFunction( ( method = value.then ) ) ) {
|
||||||
method.call( value, resolve, reject );
|
method.call( value, resolve, reject );
|
||||||
|
|
||||||
// Other non-thenables
|
// Other non-thenables
|
||||||
@ -81,14 +82,14 @@ jQuery.extend( {
|
|||||||
jQuery.each( tuples, function( i, tuple ) {
|
jQuery.each( tuples, function( i, tuple ) {
|
||||||
|
|
||||||
// Map tuples (progress, done, fail) to arguments (done, fail, progress)
|
// Map tuples (progress, done, fail) to arguments (done, fail, progress)
|
||||||
var fn = jQuery.isFunction( fns[ tuple[ 4 ] ] ) && fns[ tuple[ 4 ] ];
|
var fn = isFunction( fns[ tuple[ 4 ] ] ) && fns[ tuple[ 4 ] ];
|
||||||
|
|
||||||
// deferred.progress(function() { bind to newDefer or newDefer.notify })
|
// deferred.progress(function() { bind to newDefer or newDefer.notify })
|
||||||
// deferred.done(function() { bind to newDefer or newDefer.resolve })
|
// deferred.done(function() { bind to newDefer or newDefer.resolve })
|
||||||
// deferred.fail(function() { bind to newDefer or newDefer.reject })
|
// deferred.fail(function() { bind to newDefer or newDefer.reject })
|
||||||
deferred[ tuple[ 1 ] ]( function() {
|
deferred[ tuple[ 1 ] ]( function() {
|
||||||
var returned = fn && fn.apply( this, arguments );
|
var returned = fn && fn.apply( this, arguments );
|
||||||
if ( returned && jQuery.isFunction( returned.promise ) ) {
|
if ( returned && isFunction( returned.promise ) ) {
|
||||||
returned.promise()
|
returned.promise()
|
||||||
.progress( newDefer.notify )
|
.progress( newDefer.notify )
|
||||||
.done( newDefer.resolve )
|
.done( newDefer.resolve )
|
||||||
@ -142,7 +143,7 @@ jQuery.extend( {
|
|||||||
returned.then;
|
returned.then;
|
||||||
|
|
||||||
// Handle a returned thenable
|
// Handle a returned thenable
|
||||||
if ( jQuery.isFunction( then ) ) {
|
if ( isFunction( then ) ) {
|
||||||
|
|
||||||
// Special processors (notify) just wait for resolution
|
// Special processors (notify) just wait for resolution
|
||||||
if ( special ) {
|
if ( special ) {
|
||||||
@ -238,7 +239,7 @@ jQuery.extend( {
|
|||||||
resolve(
|
resolve(
|
||||||
0,
|
0,
|
||||||
newDefer,
|
newDefer,
|
||||||
jQuery.isFunction( onProgress ) ?
|
isFunction( onProgress ) ?
|
||||||
onProgress :
|
onProgress :
|
||||||
Identity,
|
Identity,
|
||||||
newDefer.notifyWith
|
newDefer.notifyWith
|
||||||
@ -250,7 +251,7 @@ jQuery.extend( {
|
|||||||
resolve(
|
resolve(
|
||||||
0,
|
0,
|
||||||
newDefer,
|
newDefer,
|
||||||
jQuery.isFunction( onFulfilled ) ?
|
isFunction( onFulfilled ) ?
|
||||||
onFulfilled :
|
onFulfilled :
|
||||||
Identity
|
Identity
|
||||||
)
|
)
|
||||||
@ -261,7 +262,7 @@ jQuery.extend( {
|
|||||||
resolve(
|
resolve(
|
||||||
0,
|
0,
|
||||||
newDefer,
|
newDefer,
|
||||||
jQuery.isFunction( onRejected ) ?
|
isFunction( onRejected ) ?
|
||||||
onRejected :
|
onRejected :
|
||||||
Thrower
|
Thrower
|
||||||
)
|
)
|
||||||
@ -379,7 +380,7 @@ jQuery.extend( {
|
|||||||
|
|
||||||
// Use .then() to unwrap secondary thenables (cf. gh-3000)
|
// Use .then() to unwrap secondary thenables (cf. gh-3000)
|
||||||
if ( master.state() === "pending" ||
|
if ( master.state() === "pending" ||
|
||||||
jQuery.isFunction( resolveValues[ i ] && resolveValues[ i ].then ) ) {
|
isFunction( resolveValues[ i ] && resolveValues[ i ].then ) ) {
|
||||||
|
|
||||||
return master.then();
|
return master.then();
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,10 @@ define( [
|
|||||||
"./core",
|
"./core",
|
||||||
"./core/nodeName",
|
"./core/nodeName",
|
||||||
"./core/camelCase",
|
"./core/camelCase",
|
||||||
|
"./var/isFunction",
|
||||||
"./var/isWindow",
|
"./var/isWindow",
|
||||||
"./var/slice"
|
"./var/slice"
|
||||||
], function( jQuery, nodeName, camelCase, isWindow, slice ) {
|
], function( jQuery, nodeName, camelCase, isFunction, isWindow, slice ) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -44,7 +45,7 @@ jQuery.proxy = function( fn, context ) {
|
|||||||
|
|
||||||
// Quick check to determine if target is callable, in the spec
|
// Quick check to determine if target is callable, in the spec
|
||||||
// this throws a TypeError, but we will just return undefined.
|
// this throws a TypeError, but we will just return undefined.
|
||||||
if ( !jQuery.isFunction( fn ) ) {
|
if ( !isFunction( fn ) ) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,6 +71,7 @@ jQuery.holdReady = function( hold ) {
|
|||||||
jQuery.isArray = Array.isArray;
|
jQuery.isArray = Array.isArray;
|
||||||
jQuery.parseJSON = JSON.parse;
|
jQuery.parseJSON = JSON.parse;
|
||||||
jQuery.nodeName = nodeName;
|
jQuery.nodeName = nodeName;
|
||||||
|
jQuery.isFunction = isFunction;
|
||||||
jQuery.isWindow = isWindow;
|
jQuery.isWindow = isWindow;
|
||||||
jQuery.camelCase = camelCase;
|
jQuery.camelCase = camelCase;
|
||||||
|
|
||||||
|
17
src/effects.js
vendored
17
src/effects.js
vendored
@ -2,6 +2,7 @@ define( [
|
|||||||
"./core",
|
"./core",
|
||||||
"./core/camelCase",
|
"./core/camelCase",
|
||||||
"./var/document",
|
"./var/document",
|
||||||
|
"./var/isFunction",
|
||||||
"./var/rcssNum",
|
"./var/rcssNum",
|
||||||
"./var/rnothtmlwhite",
|
"./var/rnothtmlwhite",
|
||||||
"./css/var/cssExpand",
|
"./css/var/cssExpand",
|
||||||
@ -18,8 +19,8 @@ define( [
|
|||||||
"./manipulation",
|
"./manipulation",
|
||||||
"./css",
|
"./css",
|
||||||
"./effects/Tween"
|
"./effects/Tween"
|
||||||
], function( jQuery, camelCase, document, rcssNum, rnothtmlwhite, cssExpand, isHiddenWithinTree,
|
], function( jQuery, camelCase, document, isFunction, rcssNum, rnothtmlwhite, cssExpand,
|
||||||
swap, adjustCSS, dataPriv, showHide ) {
|
isHiddenWithinTree, swap, adjustCSS, dataPriv, showHide ) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -385,7 +386,7 @@ function Animation( elem, properties, options ) {
|
|||||||
for ( ; index < length; index++ ) {
|
for ( ; index < length; index++ ) {
|
||||||
result = Animation.prefilters[ index ].call( animation, elem, props, animation.opts );
|
result = Animation.prefilters[ index ].call( animation, elem, props, animation.opts );
|
||||||
if ( result ) {
|
if ( result ) {
|
||||||
if ( jQuery.isFunction( result.stop ) ) {
|
if ( isFunction( result.stop ) ) {
|
||||||
jQuery._queueHooks( animation.elem, animation.opts.queue ).stop =
|
jQuery._queueHooks( animation.elem, animation.opts.queue ).stop =
|
||||||
result.stop.bind( result );
|
result.stop.bind( result );
|
||||||
}
|
}
|
||||||
@ -395,7 +396,7 @@ function Animation( elem, properties, options ) {
|
|||||||
|
|
||||||
jQuery.map( props, createTween, animation );
|
jQuery.map( props, createTween, animation );
|
||||||
|
|
||||||
if ( jQuery.isFunction( animation.opts.start ) ) {
|
if ( isFunction( animation.opts.start ) ) {
|
||||||
animation.opts.start.call( elem, animation );
|
animation.opts.start.call( elem, animation );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -428,7 +429,7 @@ jQuery.Animation = jQuery.extend( Animation, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
tweener: function( props, callback ) {
|
tweener: function( props, callback ) {
|
||||||
if ( jQuery.isFunction( props ) ) {
|
if ( isFunction( props ) ) {
|
||||||
callback = props;
|
callback = props;
|
||||||
props = [ "*" ];
|
props = [ "*" ];
|
||||||
} else {
|
} else {
|
||||||
@ -460,9 +461,9 @@ jQuery.Animation = jQuery.extend( Animation, {
|
|||||||
jQuery.speed = function( speed, easing, fn ) {
|
jQuery.speed = function( speed, easing, fn ) {
|
||||||
var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
|
var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
|
||||||
complete: fn || !fn && easing ||
|
complete: fn || !fn && easing ||
|
||||||
jQuery.isFunction( speed ) && speed,
|
isFunction( speed ) && speed,
|
||||||
duration: speed,
|
duration: speed,
|
||||||
easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
|
easing: fn && easing || easing && !isFunction( easing ) && easing
|
||||||
};
|
};
|
||||||
|
|
||||||
// Go to the end state if fx are off
|
// Go to the end state if fx are off
|
||||||
@ -489,7 +490,7 @@ jQuery.speed = function( speed, easing, fn ) {
|
|||||||
opt.old = opt.complete;
|
opt.old = opt.complete;
|
||||||
|
|
||||||
opt.complete = function() {
|
opt.complete = function() {
|
||||||
if ( jQuery.isFunction( opt.old ) ) {
|
if ( isFunction( opt.old ) ) {
|
||||||
opt.old.call( this );
|
opt.old.call( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ define( [
|
|||||||
"./core",
|
"./core",
|
||||||
"./var/document",
|
"./var/document",
|
||||||
"./var/documentElement",
|
"./var/documentElement",
|
||||||
|
"./var/isFunction",
|
||||||
"./var/rnothtmlwhite",
|
"./var/rnothtmlwhite",
|
||||||
"./var/slice",
|
"./var/slice",
|
||||||
"./data/var/dataPriv",
|
"./data/var/dataPriv",
|
||||||
@ -9,7 +10,8 @@ define( [
|
|||||||
|
|
||||||
"./core/init",
|
"./core/init",
|
||||||
"./selector"
|
"./selector"
|
||||||
], function( jQuery, document, documentElement, rnothtmlwhite, slice, dataPriv, nodeName ) {
|
], function( jQuery, document, isFunction, documentElement, rnothtmlwhite,
|
||||||
|
slice, dataPriv, nodeName ) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -418,7 +420,7 @@ jQuery.event = {
|
|||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: true,
|
configurable: true,
|
||||||
|
|
||||||
get: jQuery.isFunction( hook ) ?
|
get: isFunction( hook ) ?
|
||||||
function() {
|
function() {
|
||||||
if ( this.originalEvent ) {
|
if ( this.originalEvent ) {
|
||||||
return hook( this.originalEvent );
|
return hook( this.originalEvent );
|
||||||
|
@ -4,9 +4,10 @@ define( [
|
|||||||
"../data/var/dataPriv",
|
"../data/var/dataPriv",
|
||||||
"../data/var/acceptData",
|
"../data/var/acceptData",
|
||||||
"../var/hasOwn",
|
"../var/hasOwn",
|
||||||
|
"../var/isFunction",
|
||||||
"../var/isWindow",
|
"../var/isWindow",
|
||||||
"../event"
|
"../event"
|
||||||
], function( jQuery, document, dataPriv, acceptData, hasOwn, isWindow ) {
|
], function( jQuery, document, dataPriv, acceptData, hasOwn, isFunction, isWindow ) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -128,7 +129,7 @@ jQuery.extend( jQuery.event, {
|
|||||||
|
|
||||||
// Call a native DOM method on the target with the same name as the event.
|
// Call a native DOM method on the target with the same name as the event.
|
||||||
// Don't do default actions on window, that's where global variables be (#6170)
|
// Don't do default actions on window, that's where global variables be (#6170)
|
||||||
if ( ontype && jQuery.isFunction( elem[ type ] ) && !isWindow( elem ) ) {
|
if ( ontype && isFunction( elem[ type ] ) && !isWindow( elem ) ) {
|
||||||
|
|
||||||
// Don't re-trigger an onFOO event when we call its FOO() method
|
// Don't re-trigger an onFOO event when we call its FOO() method
|
||||||
tmp = elem[ ontype ];
|
tmp = elem[ ontype ];
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
define( [
|
define( [
|
||||||
"./core",
|
"./core",
|
||||||
"./var/concat",
|
"./var/concat",
|
||||||
|
"./var/isFunction",
|
||||||
"./var/push",
|
"./var/push",
|
||||||
"./core/access",
|
"./core/access",
|
||||||
"./manipulation/var/rcheckableType",
|
"./manipulation/var/rcheckableType",
|
||||||
@ -22,7 +23,7 @@ define( [
|
|||||||
"./traversing",
|
"./traversing",
|
||||||
"./selector",
|
"./selector",
|
||||||
"./event"
|
"./event"
|
||||||
], function( jQuery, concat, push, access,
|
], function( jQuery, concat, isFunction, push, access,
|
||||||
rcheckableType, rtagName, rscriptType,
|
rcheckableType, rtagName, rscriptType,
|
||||||
wrapMap, getAll, setGlobalEval, buildFragment, support,
|
wrapMap, getAll, setGlobalEval, buildFragment, support,
|
||||||
dataPriv, dataUser, acceptData, DOMEval, nodeName ) {
|
dataPriv, dataUser, acceptData, DOMEval, nodeName ) {
|
||||||
@ -131,15 +132,15 @@ function domManip( collection, args, callback, ignored ) {
|
|||||||
l = collection.length,
|
l = collection.length,
|
||||||
iNoClone = l - 1,
|
iNoClone = l - 1,
|
||||||
value = args[ 0 ],
|
value = args[ 0 ],
|
||||||
isFunction = jQuery.isFunction( value );
|
valueIsFunction = isFunction( value );
|
||||||
|
|
||||||
// We can't cloneNode fragments that contain checked, in WebKit
|
// We can't cloneNode fragments that contain checked, in WebKit
|
||||||
if ( isFunction ||
|
if ( valueIsFunction ||
|
||||||
( l > 1 && typeof value === "string" &&
|
( l > 1 && typeof value === "string" &&
|
||||||
!support.checkClone && rchecked.test( value ) ) ) {
|
!support.checkClone && rchecked.test( value ) ) ) {
|
||||||
return collection.each( function( index ) {
|
return collection.each( function( index ) {
|
||||||
var self = collection.eq( index );
|
var self = collection.eq( index );
|
||||||
if ( isFunction ) {
|
if ( valueIsFunction ) {
|
||||||
args[ 0 ] = value.call( this, index, self.html() );
|
args[ 0 ] = value.call( this, index, self.html() );
|
||||||
}
|
}
|
||||||
domManip( self, args, callback, ignored );
|
domManip( self, args, callback, ignored );
|
||||||
|
@ -3,6 +3,7 @@ define( [
|
|||||||
"./core/access",
|
"./core/access",
|
||||||
"./var/document",
|
"./var/document",
|
||||||
"./var/documentElement",
|
"./var/documentElement",
|
||||||
|
"./var/isFunction",
|
||||||
"./css/var/rnumnonpx",
|
"./css/var/rnumnonpx",
|
||||||
"./css/curCSS",
|
"./css/curCSS",
|
||||||
"./css/addGetHookIf",
|
"./css/addGetHookIf",
|
||||||
@ -11,7 +12,7 @@ define( [
|
|||||||
"./core/init",
|
"./core/init",
|
||||||
"./css",
|
"./css",
|
||||||
"./selector" // contains
|
"./selector" // contains
|
||||||
], function( jQuery, access, document, documentElement, rnumnonpx,
|
], function( jQuery, access, document, documentElement, isFunction, rnumnonpx,
|
||||||
curCSS, addGetHookIf, support, isWindow ) {
|
curCSS, addGetHookIf, support, isWindow ) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
@ -46,7 +47,7 @@ jQuery.offset = {
|
|||||||
curLeft = parseFloat( curCSSLeft ) || 0;
|
curLeft = parseFloat( curCSSLeft ) || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( jQuery.isFunction( options ) ) {
|
if ( isFunction( options ) ) {
|
||||||
|
|
||||||
// Use jQuery.extend here to allow modification of coordinates argument (gh-1848)
|
// Use jQuery.extend here to allow modification of coordinates argument (gh-1848)
|
||||||
options = options.call( elem, i, jQuery.extend( {}, curOffset ) );
|
options = options.call( elem, i, jQuery.extend( {}, curOffset ) );
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
define( [
|
define( [
|
||||||
"./core",
|
"./core",
|
||||||
"./manipulation/var/rcheckableType",
|
"./manipulation/var/rcheckableType",
|
||||||
|
"./var/isFunction",
|
||||||
"./core/init",
|
"./core/init",
|
||||||
"./traversing", // filter
|
"./traversing", // filter
|
||||||
"./attributes/prop"
|
"./attributes/prop"
|
||||||
], function( jQuery, rcheckableType ) {
|
], function( jQuery, rcheckableType, isFunction ) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -60,7 +61,7 @@ jQuery.param = function( a, traditional ) {
|
|||||||
add = function( key, valueOrFunction ) {
|
add = function( key, valueOrFunction ) {
|
||||||
|
|
||||||
// If value is a function, invoke it and use its return value
|
// If value is a function, invoke it and use its return value
|
||||||
var value = jQuery.isFunction( valueOrFunction ) ?
|
var value = isFunction( valueOrFunction ) ?
|
||||||
valueOrFunction() :
|
valueOrFunction() :
|
||||||
valueOrFunction;
|
valueOrFunction;
|
||||||
|
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
define( [
|
define( [
|
||||||
"../core",
|
"../core",
|
||||||
"../var/indexOf",
|
"../var/indexOf",
|
||||||
|
"../var/isFunction",
|
||||||
"./var/rneedsContext",
|
"./var/rneedsContext",
|
||||||
"../selector"
|
"../selector"
|
||||||
], function( jQuery, indexOf, rneedsContext ) {
|
], function( jQuery, indexOf, isFunction, rneedsContext ) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -11,7 +12,7 @@ var risSimple = /^.[^:#\[\.,]*$/;
|
|||||||
|
|
||||||
// Implement the identical functionality for filter and not
|
// Implement the identical functionality for filter and not
|
||||||
function winnow( elements, qualifier, not ) {
|
function winnow( elements, qualifier, not ) {
|
||||||
if ( jQuery.isFunction( qualifier ) ) {
|
if ( isFunction( qualifier ) ) {
|
||||||
return jQuery.grep( elements, function( elem, i ) {
|
return jQuery.grep( elements, function( elem, i ) {
|
||||||
return !!qualifier.call( elem, i, elem ) !== not;
|
return !!qualifier.call( elem, i, elem ) !== not;
|
||||||
} );
|
} );
|
||||||
|
13
src/var/isFunction.js
Normal file
13
src/var/isFunction.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
define( function() {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
return function isFunction( obj ) {
|
||||||
|
|
||||||
|
// Support: Chrome <=57, Firefox <=52
|
||||||
|
// In some browsers, typeof returns "function" for HTML <object> elements
|
||||||
|
// (i.e., `typeof document.createElement( "object" ) === "function"`).
|
||||||
|
// We don't want to classify *any* DOM node as a function.
|
||||||
|
return typeof obj === "function" && typeof obj.nodeType !== "number";
|
||||||
|
};
|
||||||
|
|
||||||
|
} );
|
11
src/wrap.js
11
src/wrap.js
@ -1,9 +1,10 @@
|
|||||||
define( [
|
define( [
|
||||||
"./core",
|
"./core",
|
||||||
|
"./var/isFunction",
|
||||||
"./core/init",
|
"./core/init",
|
||||||
"./manipulation", // clone
|
"./manipulation", // clone
|
||||||
"./traversing" // parent, contents
|
"./traversing" // parent, contents
|
||||||
], function( jQuery ) {
|
], function( jQuery, isFunction ) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -12,7 +13,7 @@ jQuery.fn.extend( {
|
|||||||
var wrap;
|
var wrap;
|
||||||
|
|
||||||
if ( this[ 0 ] ) {
|
if ( this[ 0 ] ) {
|
||||||
if ( jQuery.isFunction( html ) ) {
|
if ( isFunction( html ) ) {
|
||||||
html = html.call( this[ 0 ] );
|
html = html.call( this[ 0 ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +39,7 @@ jQuery.fn.extend( {
|
|||||||
},
|
},
|
||||||
|
|
||||||
wrapInner: function( html ) {
|
wrapInner: function( html ) {
|
||||||
if ( jQuery.isFunction( html ) ) {
|
if ( isFunction( html ) ) {
|
||||||
return this.each( function( i ) {
|
return this.each( function( i ) {
|
||||||
jQuery( this ).wrapInner( html.call( this, i ) );
|
jQuery( this ).wrapInner( html.call( this, i ) );
|
||||||
} );
|
} );
|
||||||
@ -58,10 +59,10 @@ jQuery.fn.extend( {
|
|||||||
},
|
},
|
||||||
|
|
||||||
wrap: function( html ) {
|
wrap: function( html ) {
|
||||||
var isFunction = jQuery.isFunction( html );
|
var htmlIsFunction = isFunction( html );
|
||||||
|
|
||||||
return this.each( function( i ) {
|
return this.each( function( i ) {
|
||||||
jQuery( this ).wrapAll( isFunction ? html.call( this, i ) : html );
|
jQuery( this ).wrapAll( htmlIsFunction ? html.call( this, i ) : html );
|
||||||
} );
|
} );
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ this.ajaxTest = function( title, expect, options ) {
|
|||||||
QUnit.test( title, expect, function( assert ) {
|
QUnit.test( title, expect, function( assert ) {
|
||||||
var requestOptions;
|
var requestOptions;
|
||||||
|
|
||||||
if ( jQuery.isFunction( options ) ) {
|
if ( typeof options === "function" ) {
|
||||||
options = options( assert );
|
options = options( assert );
|
||||||
}
|
}
|
||||||
options = options || [];
|
options = options || [];
|
||||||
@ -208,7 +208,7 @@ this.ajaxTest = function( title, expect, options ) {
|
|||||||
if ( !completed ) {
|
if ( !completed ) {
|
||||||
if ( !handler ) {
|
if ( !handler ) {
|
||||||
assert.ok( false, "unexpected " + status );
|
assert.ok( false, "unexpected " + status );
|
||||||
} else if ( jQuery.isFunction( handler ) ) {
|
} else if ( typeof handler === "function" ) {
|
||||||
handler.apply( this, arguments );
|
handler.apply( this, arguments );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ QUnit.test( "show/hide", function( assert ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QUnit.test( "core", function( assert ) {
|
QUnit.test( "core", function( assert ) {
|
||||||
assert.expect( 25 );
|
assert.expect( 23 );
|
||||||
|
|
||||||
var elem = jQuery( "<div></div><span></span>" );
|
var elem = jQuery( "<div></div><span></span>" );
|
||||||
|
|
||||||
@ -90,9 +90,6 @@ QUnit.test( "core", function( assert ) {
|
|||||||
assert.ok( jQuery.isPlainObject( { "a": 2 } ), "jQuery.isPlainObject(object)" );
|
assert.ok( jQuery.isPlainObject( { "a": 2 } ), "jQuery.isPlainObject(object)" );
|
||||||
assert.ok( !jQuery.isPlainObject( "foo" ), "jQuery.isPlainObject(String)" );
|
assert.ok( !jQuery.isPlainObject( "foo" ), "jQuery.isPlainObject(String)" );
|
||||||
|
|
||||||
assert.ok( jQuery.isFunction( jQuery.noop ), "jQuery.isFunction(jQuery.noop)" );
|
|
||||||
assert.ok( !jQuery.isFunction( 2 ), "jQuery.isFunction(Number)" );
|
|
||||||
|
|
||||||
assert.ok( jQuery.isNumeric( "-2" ), "jQuery.isNumeric(String representing a number)" );
|
assert.ok( jQuery.isNumeric( "-2" ), "jQuery.isNumeric(String representing a number)" );
|
||||||
assert.ok( !jQuery.isNumeric( "" ), "jQuery.isNumeric(\"\")" );
|
assert.ok( !jQuery.isNumeric( "" ), "jQuery.isNumeric(\"\")" );
|
||||||
|
|
||||||
|
@ -404,153 +404,6 @@ QUnit[ "assign" in Object ? "test" : "skip" ]( "isPlainObject(Object.assign(...)
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
QUnit.test( "isFunction", function( assert ) {
|
|
||||||
assert.expect( 20 );
|
|
||||||
|
|
||||||
var mystr, myarr, myfunction, fn, obj, nodes, first, input, a;
|
|
||||||
|
|
||||||
// Make sure that false values return false
|
|
||||||
assert.ok( !jQuery.isFunction(), "No Value" );
|
|
||||||
assert.ok( !jQuery.isFunction( null ), "null Value" );
|
|
||||||
assert.ok( !jQuery.isFunction( undefined ), "undefined Value" );
|
|
||||||
assert.ok( !jQuery.isFunction( "" ), "Empty String Value" );
|
|
||||||
assert.ok( !jQuery.isFunction( 0 ), "0 Value" );
|
|
||||||
|
|
||||||
// Check built-ins
|
|
||||||
assert.ok( jQuery.isFunction( String ), "String Function(" + String + ")" );
|
|
||||||
assert.ok( jQuery.isFunction( Array ), "Array Function(" + Array + ")" );
|
|
||||||
assert.ok( jQuery.isFunction( Object ), "Object Function(" + Object + ")" );
|
|
||||||
assert.ok( jQuery.isFunction( Function ), "Function Function(" + Function + ")" );
|
|
||||||
|
|
||||||
// When stringified, this could be misinterpreted
|
|
||||||
mystr = "function";
|
|
||||||
assert.ok( !jQuery.isFunction( mystr ), "Function String" );
|
|
||||||
|
|
||||||
// When stringified, this could be misinterpreted
|
|
||||||
myarr = [ "function" ];
|
|
||||||
assert.ok( !jQuery.isFunction( myarr ), "Function Array" );
|
|
||||||
|
|
||||||
// When stringified, this could be misinterpreted
|
|
||||||
myfunction = { "function": "test" };
|
|
||||||
assert.ok( !jQuery.isFunction( myfunction ), "Function Object" );
|
|
||||||
|
|
||||||
// Make sure normal functions still work
|
|
||||||
fn = function() {};
|
|
||||||
assert.ok( jQuery.isFunction( fn ), "Normal Function" );
|
|
||||||
|
|
||||||
assert.notOk( jQuery.isFunction( Object.create( fn ) ), "custom Function subclass" );
|
|
||||||
|
|
||||||
obj = document.createElement( "object" );
|
|
||||||
|
|
||||||
// Some versions of Firefox and Chrome say this is a function
|
|
||||||
assert.ok( !jQuery.isFunction( obj ), "Object Element" );
|
|
||||||
|
|
||||||
// Since 1.3, this isn't supported (#2968)
|
|
||||||
//ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" );
|
|
||||||
|
|
||||||
nodes = document.body.childNodes;
|
|
||||||
|
|
||||||
// Safari says this is a function
|
|
||||||
assert.ok( !jQuery.isFunction( nodes ), "childNodes Property" );
|
|
||||||
|
|
||||||
first = document.body.firstChild;
|
|
||||||
|
|
||||||
// Normal elements are reported ok everywhere
|
|
||||||
assert.ok( !jQuery.isFunction( first ), "A normal DOM Element" );
|
|
||||||
|
|
||||||
input = document.createElement( "input" );
|
|
||||||
input.type = "text";
|
|
||||||
document.body.appendChild( input );
|
|
||||||
|
|
||||||
// Since 1.3, this isn't supported (#2968)
|
|
||||||
//ok( jQuery.isFunction(input.focus), "A default function property" );
|
|
||||||
|
|
||||||
document.body.removeChild( input );
|
|
||||||
|
|
||||||
a = document.createElement( "a" );
|
|
||||||
a.href = "some-function";
|
|
||||||
document.body.appendChild( a );
|
|
||||||
|
|
||||||
// This serializes with the word 'function' in it
|
|
||||||
assert.ok( !jQuery.isFunction( a ), "Anchor Element" );
|
|
||||||
|
|
||||||
document.body.removeChild( a );
|
|
||||||
|
|
||||||
// Recursive function calls have lengths and array-like properties
|
|
||||||
function callme( callback ) {
|
|
||||||
function fn( response ) {
|
|
||||||
callback( response );
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.ok( jQuery.isFunction( fn ), "Recursive Function Call" );
|
|
||||||
|
|
||||||
fn( { some: "data" } );
|
|
||||||
}
|
|
||||||
|
|
||||||
callme( function() {
|
|
||||||
callme( function() {} );
|
|
||||||
} );
|
|
||||||
} );
|
|
||||||
|
|
||||||
QUnit.test( "isFunction(cross-realm function)", function( assert ) {
|
|
||||||
assert.expect( 1 );
|
|
||||||
|
|
||||||
var iframe, doc,
|
|
||||||
done = assert.async();
|
|
||||||
|
|
||||||
// Functions from other windows should be matched
|
|
||||||
Globals.register( "iframeDone" );
|
|
||||||
window.iframeDone = function( fn, detail ) {
|
|
||||||
window.iframeDone = undefined;
|
|
||||||
assert.ok( jQuery.isFunction( fn ), "cross-realm function" +
|
|
||||||
( detail ? " - " + detail : "" ) );
|
|
||||||
done();
|
|
||||||
};
|
|
||||||
|
|
||||||
iframe = jQuery( "#qunit-fixture" )[ 0 ].appendChild( document.createElement( "iframe" ) );
|
|
||||||
doc = iframe.contentDocument || iframe.contentWindow.document;
|
|
||||||
doc.open();
|
|
||||||
doc.write( "<body onload='window.parent.iframeDone( function() {} );'>" );
|
|
||||||
doc.close();
|
|
||||||
} );
|
|
||||||
|
|
||||||
supportjQuery.each(
|
|
||||||
{
|
|
||||||
GeneratorFunction: "function*() {}",
|
|
||||||
AsyncFunction: "async function() {}"
|
|
||||||
},
|
|
||||||
function( subclass, source ) {
|
|
||||||
var fn;
|
|
||||||
try {
|
|
||||||
fn = Function( "return " + source )();
|
|
||||||
} catch ( e ) {}
|
|
||||||
|
|
||||||
QUnit[ fn ? "test" : "skip" ]( "isFunction(" + subclass + ")",
|
|
||||||
function( assert ) {
|
|
||||||
assert.expect( 1 );
|
|
||||||
|
|
||||||
assert.equal( jQuery.isFunction( fn ), true, source );
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
QUnit[ typeof Symbol === "function" && Symbol.toStringTag ? "test" : "skip" ](
|
|
||||||
"isFunction(custom @@toStringTag)",
|
|
||||||
function( assert ) {
|
|
||||||
assert.expect( 2 );
|
|
||||||
|
|
||||||
var obj = {},
|
|
||||||
fn = function() {};
|
|
||||||
obj[ Symbol.toStringTag ] = "Function";
|
|
||||||
fn[ Symbol.toStringTag ] = "Object";
|
|
||||||
|
|
||||||
assert.equal( jQuery.isFunction( obj ), false, "function-mimicking object" );
|
|
||||||
assert.equal( jQuery.isFunction( fn ), true, "object-mimicking function" );
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
QUnit.test( "isNumeric", function( assert ) {
|
QUnit.test( "isNumeric", function( assert ) {
|
||||||
assert.expect( 43 );
|
assert.expect( 43 );
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
|
|||||||
|
|
||||||
var defer = createDeferred();
|
var defer = createDeferred();
|
||||||
|
|
||||||
assert.ok( jQuery.isFunction( defer.pipe ), "defer.pipe is a function" );
|
assert.ok( typeof defer.pipe === "function", "defer.pipe is a function" );
|
||||||
|
|
||||||
defer.resolve().done( function() {
|
defer.resolve().done( function() {
|
||||||
assert.ok( true, "Success on resolve" );
|
assert.ok( true, "Success on resolve" );
|
||||||
@ -49,7 +49,7 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
|
|||||||
assert.strictEqual( defer.promise(), promise, "promise is always the same" );
|
assert.strictEqual( defer.promise(), promise, "promise is always the same" );
|
||||||
assert.strictEqual( funcPromise, func, "non objects get extended" );
|
assert.strictEqual( funcPromise, func, "non objects get extended" );
|
||||||
jQuery.each( promise, function( key ) {
|
jQuery.each( promise, function( key ) {
|
||||||
if ( !jQuery.isFunction( promise[ key ] ) ) {
|
if ( typeof promise[ key ] !== "function" ) {
|
||||||
assert.ok( false, key + " is a function (" + jQuery.type( promise[ key ] ) + ")" );
|
assert.ok( false, key + " is a function (" + jQuery.type( promise[ key ] ) + ")" );
|
||||||
}
|
}
|
||||||
if ( promise[ key ] !== func[ key ] ) {
|
if ( promise[ key ] !== func[ key ] ) {
|
||||||
@ -1097,7 +1097,7 @@ QUnit.test( "jQuery.when - always returns a new promise", function( assert ) {
|
|||||||
}, function( label, args ) {
|
}, function( label, args ) {
|
||||||
var result = jQuery.when.apply( jQuery, args );
|
var result = jQuery.when.apply( jQuery, args );
|
||||||
|
|
||||||
assert.ok( jQuery.isFunction( result.then ), "Thenable returned from " + label );
|
assert.ok( typeof result.then === "function", "Thenable returned from " + label );
|
||||||
assert.strictEqual( result.resolve, undefined, "Non-deferred returned from " + label );
|
assert.strictEqual( result.resolve, undefined, "Non-deferred returned from " + label );
|
||||||
assert.strictEqual( result.promise(), result, "Promise returned from " + label );
|
assert.strictEqual( result.promise(), result, "Promise returned from " + label );
|
||||||
|
|
||||||
|
@ -165,6 +165,161 @@ QUnit.test( "jQuery.nodeName", function( assert ) {
|
|||||||
);
|
);
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
||||||
|
QUnit.test( "core", function( assert ) {
|
||||||
|
assert.expect( 2 );
|
||||||
|
|
||||||
|
assert.ok( jQuery.isFunction( jQuery.noop ), "jQuery.isFunction(jQuery.noop)" );
|
||||||
|
assert.ok( !jQuery.isFunction( 2 ), "jQuery.isFunction(Number)" );
|
||||||
|
} );
|
||||||
|
|
||||||
|
|
||||||
|
QUnit.test( "isFunction", function( assert ) {
|
||||||
|
assert.expect( 20 );
|
||||||
|
|
||||||
|
var mystr, myarr, myfunction, fn, obj, nodes, first, input, a;
|
||||||
|
|
||||||
|
// Make sure that false values return false
|
||||||
|
assert.ok( !jQuery.isFunction(), "No Value" );
|
||||||
|
assert.ok( !jQuery.isFunction( null ), "null Value" );
|
||||||
|
assert.ok( !jQuery.isFunction( undefined ), "undefined Value" );
|
||||||
|
assert.ok( !jQuery.isFunction( "" ), "Empty String Value" );
|
||||||
|
assert.ok( !jQuery.isFunction( 0 ), "0 Value" );
|
||||||
|
|
||||||
|
// Check built-ins
|
||||||
|
assert.ok( jQuery.isFunction( String ), "String Function(" + String + ")" );
|
||||||
|
assert.ok( jQuery.isFunction( Array ), "Array Function(" + Array + ")" );
|
||||||
|
assert.ok( jQuery.isFunction( Object ), "Object Function(" + Object + ")" );
|
||||||
|
assert.ok( jQuery.isFunction( Function ), "Function Function(" + Function + ")" );
|
||||||
|
|
||||||
|
// When stringified, this could be misinterpreted
|
||||||
|
mystr = "function";
|
||||||
|
assert.ok( !jQuery.isFunction( mystr ), "Function String" );
|
||||||
|
|
||||||
|
// When stringified, this could be misinterpreted
|
||||||
|
myarr = [ "function" ];
|
||||||
|
assert.ok( !jQuery.isFunction( myarr ), "Function Array" );
|
||||||
|
|
||||||
|
// When stringified, this could be misinterpreted
|
||||||
|
myfunction = { "function": "test" };
|
||||||
|
assert.ok( !jQuery.isFunction( myfunction ), "Function Object" );
|
||||||
|
|
||||||
|
// Make sure normal functions still work
|
||||||
|
fn = function() {};
|
||||||
|
assert.ok( jQuery.isFunction( fn ), "Normal Function" );
|
||||||
|
|
||||||
|
assert.notOk( jQuery.isFunction( Object.create( fn ) ), "custom Function subclass" );
|
||||||
|
|
||||||
|
obj = document.createElement( "object" );
|
||||||
|
|
||||||
|
// Some versions of Firefox and Chrome say this is a function
|
||||||
|
assert.ok( !jQuery.isFunction( obj ), "Object Element" );
|
||||||
|
|
||||||
|
// Since 1.3, this isn't supported (#2968)
|
||||||
|
//ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" );
|
||||||
|
|
||||||
|
nodes = document.body.childNodes;
|
||||||
|
|
||||||
|
// Safari says this is a function
|
||||||
|
assert.ok( !jQuery.isFunction( nodes ), "childNodes Property" );
|
||||||
|
|
||||||
|
first = document.body.firstChild;
|
||||||
|
|
||||||
|
// Normal elements are reported ok everywhere
|
||||||
|
assert.ok( !jQuery.isFunction( first ), "A normal DOM Element" );
|
||||||
|
|
||||||
|
input = document.createElement( "input" );
|
||||||
|
input.type = "text";
|
||||||
|
document.body.appendChild( input );
|
||||||
|
|
||||||
|
// Since 1.3, this isn't supported (#2968)
|
||||||
|
//ok( jQuery.isFunction(input.focus), "A default function property" );
|
||||||
|
|
||||||
|
document.body.removeChild( input );
|
||||||
|
|
||||||
|
a = document.createElement( "a" );
|
||||||
|
a.href = "some-function";
|
||||||
|
document.body.appendChild( a );
|
||||||
|
|
||||||
|
// This serializes with the word 'function' in it
|
||||||
|
assert.ok( !jQuery.isFunction( a ), "Anchor Element" );
|
||||||
|
|
||||||
|
document.body.removeChild( a );
|
||||||
|
|
||||||
|
// Recursive function calls have lengths and array-like properties
|
||||||
|
function callme( callback ) {
|
||||||
|
function fn( response ) {
|
||||||
|
callback( response );
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.ok( jQuery.isFunction( fn ), "Recursive Function Call" );
|
||||||
|
|
||||||
|
fn( { some: "data" } );
|
||||||
|
}
|
||||||
|
|
||||||
|
callme( function() {
|
||||||
|
callme( function() {} );
|
||||||
|
} );
|
||||||
|
} );
|
||||||
|
|
||||||
|
QUnit.test( "isFunction(cross-realm function)", function( assert ) {
|
||||||
|
assert.expect( 1 );
|
||||||
|
|
||||||
|
var iframe, doc,
|
||||||
|
done = assert.async();
|
||||||
|
|
||||||
|
// Functions from other windows should be matched
|
||||||
|
Globals.register( "iframeDone" );
|
||||||
|
window.iframeDone = function( fn, detail ) {
|
||||||
|
window.iframeDone = undefined;
|
||||||
|
assert.ok( jQuery.isFunction( fn ), "cross-realm function" +
|
||||||
|
( detail ? " - " + detail : "" ) );
|
||||||
|
done();
|
||||||
|
};
|
||||||
|
|
||||||
|
iframe = jQuery( "#qunit-fixture" )[ 0 ].appendChild( document.createElement( "iframe" ) );
|
||||||
|
doc = iframe.contentDocument || iframe.contentWindow.document;
|
||||||
|
doc.open();
|
||||||
|
doc.write( "<body onload='window.parent.iframeDone( function() {} );'>" );
|
||||||
|
doc.close();
|
||||||
|
} );
|
||||||
|
|
||||||
|
supportjQuery.each(
|
||||||
|
{
|
||||||
|
GeneratorFunction: "function*() {}",
|
||||||
|
AsyncFunction: "async function() {}"
|
||||||
|
},
|
||||||
|
function( subclass, source ) {
|
||||||
|
var fn;
|
||||||
|
try {
|
||||||
|
fn = Function( "return " + source )();
|
||||||
|
} catch ( e ) {}
|
||||||
|
|
||||||
|
QUnit[ fn ? "test" : "skip" ]( "isFunction(" + subclass + ")",
|
||||||
|
function( assert ) {
|
||||||
|
assert.expect( 1 );
|
||||||
|
|
||||||
|
assert.equal( jQuery.isFunction( fn ), true, source );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
QUnit[ typeof Symbol === "function" && Symbol.toStringTag ? "test" : "skip" ](
|
||||||
|
"isFunction(custom @@toStringTag)",
|
||||||
|
function( assert ) {
|
||||||
|
assert.expect( 2 );
|
||||||
|
|
||||||
|
var obj = {},
|
||||||
|
fn = function() {};
|
||||||
|
obj[ Symbol.toStringTag ] = "Function";
|
||||||
|
fn[ Symbol.toStringTag ] = "Object";
|
||||||
|
|
||||||
|
assert.equal( jQuery.isFunction( obj ), false, "function-mimicking object" );
|
||||||
|
assert.equal( jQuery.isFunction( fn ), true, "object-mimicking function" );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
QUnit.test( "jQuery.isWindow", function( assert ) {
|
QUnit.test( "jQuery.isWindow", function( assert ) {
|
||||||
assert.expect( 14 );
|
assert.expect( 14 );
|
||||||
|
|
||||||
|
2
test/unit/effects.js
vendored
2
test/unit/effects.js
vendored
@ -2507,7 +2507,7 @@ function testEasing( assert, speed, easing, complete ) {
|
|||||||
|
|
||||||
assert.equal( options.duration, 10, "Duration set properly" );
|
assert.equal( options.duration, 10, "Duration set properly" );
|
||||||
assert.equal(
|
assert.equal(
|
||||||
jQuery.isFunction( options.easing ) ? options.easing() : options.easing,
|
typeof options.easing === "function" ? options.easing() : options.easing,
|
||||||
"linear",
|
"linear",
|
||||||
"Easing set properly"
|
"Easing set properly"
|
||||||
);
|
);
|
||||||
|
@ -1415,7 +1415,7 @@ QUnit.test( "jQuery.clone() (#8017)", function( assert ) {
|
|||||||
|
|
||||||
assert.expect( 2 );
|
assert.expect( 2 );
|
||||||
|
|
||||||
assert.ok( jQuery.clone && jQuery.isFunction( jQuery.clone ), "jQuery.clone() utility exists and is a function." );
|
assert.ok( jQuery.clone && typeof jQuery.clone === "function", "jQuery.clone() utility exists and is a function." );
|
||||||
|
|
||||||
var main = jQuery( "#qunit-fixture" )[ 0 ],
|
var main = jQuery( "#qunit-fixture" )[ 0 ],
|
||||||
clone = jQuery.clone( main );
|
clone = jQuery.clone( main );
|
||||||
|
@ -261,7 +261,7 @@ QUnit.test( ".promise(obj)", function( assert ) {
|
|||||||
var obj = {},
|
var obj = {},
|
||||||
promise = jQuery( "#foo" ).promise( "promise", obj );
|
promise = jQuery( "#foo" ).promise( "promise", obj );
|
||||||
|
|
||||||
assert.ok( jQuery.isFunction( promise.promise ), ".promise(type, obj) returns a promise" );
|
assert.ok( typeof promise.promise === "function", ".promise(type, obj) returns a promise" );
|
||||||
assert.strictEqual( promise, obj, ".promise(type, obj) returns obj" );
|
assert.strictEqual( promise, obj, ".promise(type, obj) returns obj" );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user