diff options
author | Jason Bedard <jason+github@jbedard.ca> | 2018-01-14 00:46:20 -0800 |
---|---|---|
committer | Timmy Willison <4timmywil@gmail.com> | 2018-01-16 10:39:08 -0500 |
commit | 1ea092a54b00aa4d902f4e22ada3854d195d4a18 (patch) | |
tree | 705d445aa449743e06e6354bb3f746076700e31f /src | |
parent | 91fb18190e5ab9821e3c74b6aecbb5d197c6c5f6 (diff) | |
download | jquery-1ea092a54b00aa4d902f4e22ada3854d195d4a18.tar.gz jquery-1ea092a54b00aa4d902f4e22ada3854d195d4a18.zip |
Core: deprecate jQuery.type
Fixes gh-3605
Close gh-3895
Diffstat (limited to 'src')
-rw-r--r-- | src/callbacks.js | 5 | ||||
-rw-r--r-- | src/core.js | 18 | ||||
-rw-r--r-- | src/core/access.js | 5 | ||||
-rw-r--r-- | src/core/toType.js | 20 | ||||
-rw-r--r-- | src/deprecated.js | 4 | ||||
-rw-r--r-- | src/manipulation/buildFragment.js | 5 | ||||
-rw-r--r-- | src/serialize.js | 5 |
7 files changed, 39 insertions, 23 deletions
diff --git a/src/callbacks.js b/src/callbacks.js index 78e9b4fd0..6cf54031e 100644 --- a/src/callbacks.js +++ b/src/callbacks.js @@ -1,8 +1,9 @@ define( [ "./core", + "./core/toType", "./var/isFunction", "./var/rnothtmlwhite" -], function( jQuery, isFunction, rnothtmlwhite ) { +], function( jQuery, toType, isFunction, rnothtmlwhite ) { "use strict"; @@ -130,7 +131,7 @@ jQuery.Callbacks = function( options ) { 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 ); diff --git a/src/core.js b/src/core.js index 8ffc4e516..7a016121c 100644 --- a/src/core.js +++ b/src/core.js @@ -18,10 +18,11 @@ define( [ "./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"; @@ -237,17 +238,6 @@ jQuery.extend( { 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 ); @@ -395,7 +385,7 @@ function isArrayLike( obj ) { // 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; diff --git a/src/core/access.js b/src/core/access.js index 2e1eb4121..842c4a42b 100644 --- a/src/core/access.js +++ b/src/core/access.js @@ -1,7 +1,8 @@ define( [ "../core", + "../core/toType", "../var/isFunction" -], function( jQuery, isFunction ) { +], function( jQuery, toType, isFunction ) { "use strict"; @@ -13,7 +14,7 @@ var access = function( elems, fn, key, value, chainable, emptyGet, raw ) { 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 ); diff --git a/src/core/toType.js b/src/core/toType.js new file mode 100644 index 000000000..c77ba95ad --- /dev/null +++ b/src/core/toType.js @@ -0,0 +1,20 @@ +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; +} ); diff --git a/src/deprecated.js b/src/deprecated.js index f1b7db7c6..c11b0d332 100644 --- a/src/deprecated.js +++ b/src/deprecated.js @@ -2,12 +2,13 @@ define( [ "./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"; @@ -76,6 +77,7 @@ jQuery.nodeName = nodeName; jQuery.isFunction = isFunction; jQuery.isWindow = isWindow; jQuery.camelCase = camelCase; +jQuery.type = toType; jQuery.now = Date.now; diff --git a/src/manipulation/buildFragment.js b/src/manipulation/buildFragment.js index bcb508531..782de0c61 100644 --- a/src/manipulation/buildFragment.js +++ b/src/manipulation/buildFragment.js @@ -1,11 +1,12 @@ 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"; @@ -24,7 +25,7 @@ function buildFragment( elems, context, scripts, selection, ignored ) { 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 diff --git a/src/serialize.js b/src/serialize.js index 635d5b646..30fcf98cc 100644 --- a/src/serialize.js +++ b/src/serialize.js @@ -1,11 +1,12 @@ 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"; @@ -39,7 +40,7 @@ function buildParams( prefix, obj, traditional, add ) { } } ); - } else if ( !traditional && jQuery.type( obj ) === "object" ) { + } else if ( !traditional && toType( obj ) === "object" ) { // Serialize object item. for ( name in obj ) { |