Skip to content

Commit 7ed0901

Browse files
committed
All: Switch from $.isFunction( x ) to typeof x === "function"
jQuery.isFunction will be removed in jQuery 4.0.
1 parent d0f9ef1 commit 7ed0901

File tree

10 files changed

+29
-29
lines changed

10 files changed

+29
-29
lines changed

tests/lib/common.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ function testWidgetDefaults( widget, defaults ) {
1313
var count = 0;
1414
$.each( defaults, function( key, val ) {
1515
assert.expect( ++count );
16-
if ( $.isFunction( val ) ) {
17-
assert.ok( $.isFunction( pluginDefaults[ key ] ), key );
16+
if ( typeof val === "function" ) {
17+
assert.ok( typeof pluginDefaults[ key ] === "function", key );
1818
return;
1919
}
2020
assert.deepEqual( pluginDefaults[ key ], val, key );

tests/unit/widget/core.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ QUnit.test( "widget creation", function( assert ) {
2929
};
3030

3131
$.widget( "ui.testWidget", myPrototype );
32-
assert.ok( $.isFunction( $.ui.testWidget ), "constructor was created" );
32+
assert.ok( typeof $.ui.testWidget === "function", "constructor was created" );
3333
assert.equal( typeof $.ui.testWidget.prototype, "object", "prototype was created" );
3434
method = "_create";
3535
$.ui.testWidget.prototype._create();
@@ -947,7 +947,7 @@ QUnit.test( "_on() with delegate", function( assert ) {
947947
this.element = {
948948
on: function( event, handler ) {
949949
assert.equal( event, "click.testWidget" + uuid );
950-
assert.ok( $.isFunction( handler ) );
950+
assert.ok( typeof handler === "function" );
951951
},
952952
trigger: $.noop
953953
};
@@ -956,7 +956,7 @@ QUnit.test( "_on() with delegate", function( assert ) {
956956
on: function( event, selector, handler ) {
957957
assert.equal( selector, "a" );
958958
assert.equal( event, "click.testWidget" + uuid );
959-
assert.ok( $.isFunction( handler ) );
959+
assert.ok( typeof handler === "function" );
960960
}
961961
};
962962
};
@@ -969,7 +969,7 @@ QUnit.test( "_on() with delegate", function( assert ) {
969969
on: function( event, selector, handler ) {
970970
assert.equal( selector, "form fieldset > input" );
971971
assert.equal( event, "change.testWidget" + uuid );
972-
assert.ok( $.isFunction( handler ) );
972+
assert.ok( typeof handler === "function" );
973973
}
974974
};
975975
};
@@ -1608,7 +1608,7 @@ QUnit.test( "$.widget.bridge()", function( assert ) {
16081608

16091609
$.widget.bridge( "testWidget", TestWidget );
16101610

1611-
assert.ok( $.isFunction( $.fn.testWidget ), "jQuery plugin was created" );
1611+
assert.ok( typeof $.fn.testWidget === "function", "jQuery plugin was created" );
16121612

16131613
assert.strictEqual( elem.testWidget( { foo: "bar" } ), elem, "plugin returns original jQuery object" );
16141614
instance = elem.data( "testWidget" );

ui/effect.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,7 @@ function _normalizeArguments( effect, options, speed, callback ) {
12901290
}
12911291

12921292
// Catch (effect, callback)
1293-
if ( $.isFunction( options ) ) {
1293+
if ( typeof options === "function" ) {
12941294
callback = options;
12951295
speed = null;
12961296
options = {};
@@ -1304,7 +1304,7 @@ function _normalizeArguments( effect, options, speed, callback ) {
13041304
}
13051305

13061306
// Catch (effect, options, callback)
1307-
if ( $.isFunction( speed ) ) {
1307+
if ( typeof speed === "function" ) {
13081308
callback = speed;
13091309
speed = null;
13101310
}
@@ -1338,7 +1338,7 @@ function standardAnimationOption( option ) {
13381338
}
13391339

13401340
// Complete callback
1341-
if ( $.isFunction( option ) ) {
1341+
if ( typeof option === "function" ) {
13421342
return true;
13431343
}
13441344

@@ -1383,7 +1383,7 @@ $.fn.extend( {
13831383
$.effects.saveStyle( el );
13841384
}
13851385

1386-
if ( $.isFunction( next ) ) {
1386+
if ( typeof next === "function" ) {
13871387
next();
13881388
}
13891389
};
@@ -1418,11 +1418,11 @@ $.fn.extend( {
14181418
}
14191419

14201420
function done() {
1421-
if ( $.isFunction( complete ) ) {
1421+
if ( typeof complete === "function" ) {
14221422
complete.call( elem[ 0 ] );
14231423
}
14241424

1425-
if ( $.isFunction( next ) ) {
1425+
if ( typeof next === "function" ) {
14261426
next();
14271427
}
14281428
}
@@ -1543,7 +1543,7 @@ $.fn.extend( {
15431543
} )
15441544
.animate( animation, options.duration, options.easing, function() {
15451545
transfer.remove();
1546-
if ( $.isFunction( done ) ) {
1546+
if ( typeof done === "function" ) {
15471547
done();
15481548
}
15491549
} );

ui/widget.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ $.widget = function( name, base, prototype ) {
105105
// inheriting from
106106
basePrototype.options = $.widget.extend( {}, basePrototype.options );
107107
$.each( prototype, function( prop, value ) {
108-
if ( !$.isFunction( value ) ) {
108+
if ( typeof value !== "function" ) {
109109
proxiedPrototype[ prop ] = value;
110110
return;
111111
}
@@ -233,7 +233,7 @@ $.widget.bridge = function( name, object ) {
233233
"attempted to call method '" + options + "'" );
234234
}
235235

236-
if ( !$.isFunction( instance[ options ] ) || options.charAt( 0 ) === "_" ) {
236+
if ( typeof instance[ options ] !== "function" || options.charAt( 0 ) === "_" ) {
237237
return $.error( "no such method '" + options + "' for " + name +
238238
" widget instance" );
239239
}
@@ -694,7 +694,7 @@ $.Widget.prototype = {
694694
}
695695

696696
this.element.trigger( event, data );
697-
return !( $.isFunction( callback ) &&
697+
return !( typeof callback === "function" &&
698698
callback.apply( this.element[ 0 ], [ event ].concat( data ) ) === false ||
699699
event.isDefaultPrevented() );
700700
}

ui/widgets/button.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ if ( $.uiBackCompat !== false ) {
373373
"attempted to call method '" + options + "'" );
374374
}
375375

376-
if ( !$.isFunction( instance[ options ] ) || options.charAt( 0 ) === "_" ) {
376+
if ( typeof instance[ options ] !== "function" || options.charAt( 0 ) === "_" ) {
377377
return $.error( "no such method '" + options + "' for button" +
378378
" widget instance" );
379379
}

ui/widgets/dialog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ $.widget( "ui.dialog", {
488488

489489
$.each( buttons, function( name, props ) {
490490
var click, buttonOptions;
491-
props = $.isFunction( props ) ?
491+
props = typeof props === "function" ?
492492
{ click: props, text: name } :
493493
props;
494494

ui/widgets/draggable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ $.widget( "ui.draggable", $.ui.mouse, {
296296

297297
if ( ( this.options.revert === "invalid" && !dropped ) ||
298298
( this.options.revert === "valid" && dropped ) ||
299-
this.options.revert === true || ( $.isFunction( this.options.revert ) &&
299+
this.options.revert === true || ( typeof this.options.revert === "function" &&
300300
this.options.revert.call( this.element, dropped ) )
301301
) {
302302
$( this.helper ).animate(
@@ -368,7 +368,7 @@ $.widget( "ui.draggable", $.ui.mouse, {
368368
_createHelper: function( event ) {
369369

370370
var o = this.options,
371-
helperIsFunction = $.isFunction( o.helper ),
371+
helperIsFunction = typeof o.helper === "function",
372372
helper = helperIsFunction ?
373373
$( o.helper.apply( this.element[ 0 ], [ event ] ) ) :
374374
( o.helper === "clone" ?

ui/widgets/droppable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ $.widget( "ui.droppable", {
5757
this.isover = false;
5858
this.isout = true;
5959

60-
this.accept = $.isFunction( accept ) ? accept : function( d ) {
60+
this.accept = typeof accept === "function" ? accept : function( d ) {
6161
return d.is( accept );
6262
};
6363

@@ -109,7 +109,7 @@ $.widget( "ui.droppable", {
109109
_setOption: function( key, value ) {
110110

111111
if ( key === "accept" ) {
112-
this.accept = $.isFunction( value ) ? value : function( d ) {
112+
this.accept = typeof value === "function" ? value : function( d ) {
113113
return d.is( value );
114114
};
115115
} else if ( key === "scope" ) {

ui/widgets/sortable.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ return $.widget( "ui.sortable", $.ui.mouse, {
756756
for ( j = cur.length - 1; j >= 0; j-- ) {
757757
inst = $.data( cur[ j ], this.widgetFullName );
758758
if ( inst && inst !== this && !inst.options.disabled ) {
759-
queries.push( [ $.isFunction( inst.options.items ) ?
759+
queries.push( [ typeof inst.options.items === "function" ?
760760
inst.options.items.call( inst.element ) :
761761
$( inst.options.items, inst.element )
762762
.not( ".ui-sortable-helper" )
@@ -766,7 +766,7 @@ return $.widget( "ui.sortable", $.ui.mouse, {
766766
}
767767
}
768768

769-
queries.push( [ $.isFunction( this.options.items ) ?
769+
queries.push( [ typeof this.options.items === "function" ?
770770
this.options.items
771771
.call( this.element, null, { options: this.options, item: this.currentItem } ) :
772772
$( this.options.items, this.element )
@@ -806,7 +806,7 @@ return $.widget( "ui.sortable", $.ui.mouse, {
806806

807807
var i, j, cur, inst, targetData, _queries, item, queriesLength,
808808
items = this.items,
809-
queries = [ [ $.isFunction( this.options.items ) ?
809+
queries = [ [ typeof this.options.items === "function" ?
810810
this.options.items.call( this.element[ 0 ], event, { item: this.currentItem } ) :
811811
$( this.options.items, this.element ), this ] ],
812812
connectWith = this._connectWith();
@@ -818,7 +818,7 @@ return $.widget( "ui.sortable", $.ui.mouse, {
818818
for ( j = cur.length - 1; j >= 0; j-- ) {
819819
inst = $.data( cur[ j ], this.widgetFullName );
820820
if ( inst && inst !== this && !inst.options.disabled ) {
821-
queries.push( [ $.isFunction( inst.options.items ) ?
821+
queries.push( [ typeof inst.options.items === "function" ?
822822
inst.options.items
823823
.call( inst.element[ 0 ], event, { item: this.currentItem } ) :
824824
$( inst.options.items, inst.element ), inst ] );
@@ -1121,7 +1121,7 @@ return $.widget( "ui.sortable", $.ui.mouse, {
11211121
_createHelper: function( event ) {
11221122

11231123
var o = this.options,
1124-
helper = $.isFunction( o.helper ) ?
1124+
helper = typeof o.helper === "function" ?
11251125
$( o.helper.apply( this.element[ 0 ], [ event, this.currentItem ] ) ) :
11261126
( o.helper === "clone" ? this.currentItem.clone() : this.currentItem );
11271127

ui/widgets/spinner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ $.widget( "ui.spinner", {
344344
var incremental = this.options.incremental;
345345

346346
if ( incremental ) {
347-
return $.isFunction( incremental ) ?
347+
return typeof incremental === "function" ?
348348
incremental( i ) :
349349
Math.floor( i * i * i / 50000 - i * i / 500 + 17 * i / 200 + 1 );
350350
}

0 commit comments

Comments
 (0)