Side navigation
Ticket #3618: 3618.diff
File 3618.diff, 10.2 KB (added by john, November 17, 2008 04:11PM UTC)
3618.diff - Changes all primitive checks to use typeof, removed use of isType, converted isArray and isFunction to new style.
Index: src/core.js
===================================================================
--- src/core.js (revision 5946)
+++ src/core.js (working copy)
@@ -41,7 +41,7 @@
return this;
}
// Handle HTML strings
- if ( typeof selector == "string" ) {
+ if ( typeof selector === "string" ) {
// Are we dealing with HTML string or an ID?
var match = quickExpr.exec( selector );
@@ -150,7 +150,7 @@
var options = name;
// Look for the case where we're accessing a style value
- if ( name.constructor == String )
+ if ( typeof name === "string" )
if ( value === undefined )
return this[0] && jQuery[ type || "attr" ]( this[0], name );
@@ -180,7 +180,7 @@
},
text: function( text ) {
- if ( typeof text != "object" && text != null )
+ if ( typeof text !== "object" && text != null )
return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
var ret = "";
@@ -323,7 +323,7 @@
},
not: function( selector ) {
- if ( selector.constructor == String )
+ if ( typeof selector === "string" )
// test special case where just one selector is passed in
if ( isSimple.test( selector ) )
return this.pushStack( jQuery.multiFilter( selector, this, true ) );
@@ -339,7 +339,7 @@
add: function( selector ) {
return this.pushStack( jQuery.unique( jQuery.merge(
this.get(),
- typeof selector == 'string' ?
+ typeof selector === "string" ?
jQuery( selector ) :
jQuery.makeArray( selector )
)));
@@ -400,7 +400,7 @@
return undefined;
}
- if( value.constructor == Number )
+ if ( typeof value === "number" )
value += '';
return this.each(function(){
@@ -550,7 +550,7 @@
var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
// Handle a deep copy situation
- if ( target.constructor == Boolean ) {
+ if ( typeof target === "boolean" ) {
deep = target;
target = arguments[1] || {};
// skip the boolean and the target
@@ -558,7 +558,7 @@
}
// Handle case when target is a string or something (possible in deep copy)
- if ( typeof target != "object" && typeof target != "function" )
+ if ( typeof target !== "object" && !jQuery.isFunction(target) )
target = {};
// extend jQuery itself if only one argument is passed
@@ -579,7 +579,7 @@
continue;
// Recurse if we're merging object values
- if ( deep && copy && typeof copy == "object" && !copy.nodeType )
+ if ( deep && copy && typeof copy === "object" && !copy.nodeType )
target[ name ] = jQuery.extend( deep,
// Never move original objects, clone them
src || ( copy.length != null ? [ ] : { } )
@@ -599,7 +599,8 @@
// exclude the following css properties to add px
exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
// cache defaultView
- defaultView = document.defaultView || {};
+ defaultView = document.defaultView || {},
+ toString = Object.prototype.toString;
jQuery.extend({
noConflict: function( deep ) {
@@ -611,19 +612,15 @@
return jQuery;
},
- // See test/unit/core.js for details concerning this function.
+ // See test/unit/core.js for details concerning isFunction.
// Since version 1.3, DOM methods and functions like alert
// aren't supported. They return false on IE (#2968).
-
- // Memory leaks appear in IE6 when applying instanceof
- // to the window, document or any other COM object (#3485)
- // http://ajaxian.com/archives/working-aroung-the-instanceof-memory-leak
- isFunction: function( fn ) {
- return !!fn && !!fn.hasOwnProperty && fn instanceof Function;
+ isFunction: function( obj ) {
+ return toString.call(obj) === "[object Function]";
},
-
- isArray: function( arr ){
- return !!arr && arr.constructor == Array;
+
+ isArray: function( obj ) {
+ return toString.call(obj) === "[object Array]";
},
// check if an element is in a (or is an) XML document
@@ -761,7 +758,7 @@
value = value.call( elem, i );
// Handle passing in a number to a CSS property
- return value && value.constructor == Number && type == "curCSS" && !exclude.test( name ) ?
+ return typeof value === "number" && type == "curCSS" && !exclude.test( name ) ?
value + "px" :
value;
},
@@ -946,19 +943,20 @@
clean: function( elems, context ) {
var ret = [];
context = context || document;
+
// !context.createElement fails in IE with an error but returns typeof 'object'
- if (typeof context.createElement == 'undefined')
+ if ( typeof context.createElement === "undefined" )
context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
jQuery.each(elems, function(i, elem){
- if ( typeof elem == 'number' )
+ if ( typeof elem === "number" )
elem += '';
if ( !elem )
return;
// Convert html string into DOM nodes
- if ( typeof elem == "string" ) {
+ if ( typeof elem === "string" ) {
// Fix "XHTML"-style tags in all browsers
elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ?
@@ -1139,7 +1137,7 @@
if( array != null ){
var i = array.length;
// The window, strings (and functions) also have 'length'
- if( i == null || typeof array == 'string' || jQuery.isFunction(array) || array.setInterval )
+ if( i == null || typeof array === "string" || jQuery.isFunction(array) || array.setInterval )
ret[0] = array;
else
while( i )
@@ -1369,7 +1367,7 @@
(this.length ? jQuery.css( this[0], type ) : null) :
// Set the width or height on the element (default to pixels if value is unitless)
- this.css( type, size.constructor == String ? size : size + "px" );
+ this.css( type, typeof size === "string" ? size : size + "px" );
};
});
Index: src/fx.js
===================================================================
--- src/fx.js (revision 5946)
+++ src/fx.js (working copy)
@@ -117,7 +117,7 @@
type = "fx";
}
- if ( !type || (typeof type == "string" && !fn) )
+ if ( !type || (typeof type === "string" && !fn) )
return queue( this[0], type );
return this.each(function(){
@@ -201,14 +201,14 @@
jQuery.extend({
speed: function(speed, easing, fn) {
- var opt = speed && speed.constructor == Object ? speed : {
+ var opt = typeof speed === "object" ? speed : {
complete: fn || !fn && easing ||
jQuery.isFunction( speed ) && speed,
duration: speed,
- easing: fn && easing || easing && easing.constructor != Function && easing
+ easing: fn && easing || jQuery.isFunction(easing) && easing
};
- opt.duration = jQuery.fx.off ? 0 : typeof opt.duration == 'number' ? opt.duration :
+ opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
jQuery.fx.speeds[opt.duration] || jQuery.fx.speeds._default;
// Queueing
Index: src/selector.js
===================================================================
--- src/selector.js (revision 5946)
+++ src/selector.js (working copy)
@@ -92,7 +92,7 @@
find: function( t, context ) {
// Quickly handle non-string expressions
- if ( typeof t != "string" )
+ if ( typeof t !== "string" )
return [ t ];
// check to make sure context is a DOM element or a document
@@ -214,7 +214,7 @@
// Do a quick check for the existence of the actual ID attribute
// to avoid selecting by the name attribute in IE
// also check to insure id is a string to avoid selecting an element with the name of 'id' inside a form
- if ( (jQuery.browser.msie||jQuery.browser.opera) && oid && typeof oid.id == "string" && oid.id != m[2] )
+ if ( (jQuery.browser.msie||jQuery.browser.opera) && oid && typeof oid.id === "string" && oid.id != m[2] )
oid = jQuery('[@id="'+m[2]+'"]', elem)[0];
// Do a quick check for node name (where applicable) so
@@ -391,10 +391,10 @@
// Otherwise, find the expression to execute
} else {
var fn = jQuery.expr[ m[1] ];
- if ( typeof fn == "object" )
+ if ( typeof fn === "object" )
fn = fn[ m[2] ];
- if ( typeof fn == "string" )
+ if ( typeof fn === "string" )
fn = eval("false||function(a,i){return " + fn + ";}");
// Execute it against the current filter
Index: src/event.js
===================================================================
--- src/event.js (revision 5946)
+++ src/event.js (working copy)
@@ -40,7 +40,7 @@
handle = jQuery.data(elem, "handle") || jQuery.data(elem, "handle", function(){
// Handle the second event of a trigger and when
// an event is called after a page has unloaded
- if ( typeof jQuery != "undefined" && !jQuery.event.triggered )
+ if ( typeof jQuery !== "undefined" && !jQuery.event.triggered )
return jQuery.event.handle.apply(arguments.callee.elem, arguments);
});
// Add elem as a property of the handle function
@@ -99,7 +99,7 @@
if ( events ) {
// Unbind all events for the element
- if ( types == undefined || (typeof types == "string" && types.charAt(0) == ".") )
+ if ( types == undefined || (typeof types === "string" && types.charAt(0) == ".") )
for ( var type in events )
this.remove( elem, type + (types || "") );
else {
Index: src/ajax.js
===================================================================
--- src/ajax.js (revision 5946)
+++ src/ajax.js (working copy)
@@ -3,7 +3,7 @@
_load: jQuery.fn.load,
load: function( url, params, callback ) {
- if ( typeof url != 'string' )
+ if ( typeof url !== "string" )
return this._load( url );
var off = url.indexOf(" ");
@@ -24,7 +24,7 @@
params = null;
// Otherwise, build a param string
- } else if( typeof params == 'object' ) {
+ } else if( typeof params === "object" ) {
params = jQuery.param( params );
type = "POST";
}
@@ -178,7 +178,7 @@
type = s.type.toUpperCase();
// convert data if not already a string
- if ( s.data && s.processData && typeof s.data != "string" )
+ if ( s.data && s.processData && typeof s.data !== "string" )
s.data = jQuery.param(s.data);
// Handle JSONP Parameter Callbacks
@@ -490,7 +490,7 @@
data = s.dataFilter( data, type );
// The filter can actually parse the response
- if( typeof data == 'string' ){
+ if( typeof data === "string" ){
// If the type is "script", eval it in global context
if ( type == "script" )
Download in other formats:
Original Format
File 3618.diff, 10.2 KB (added by john, November 17, 2008 04:11PM UTC)
3618.diff - Changes all primitive checks to use typeof, removed use of isType, converted isArray and isFunction to new style.
Index: src/core.js
===================================================================
--- src/core.js (revision 5946)
+++ src/core.js (working copy)
@@ -41,7 +41,7 @@
return this;
}
// Handle HTML strings
- if ( typeof selector == "string" ) {
+ if ( typeof selector === "string" ) {
// Are we dealing with HTML string or an ID?
var match = quickExpr.exec( selector );
@@ -150,7 +150,7 @@
var options = name;
// Look for the case where we're accessing a style value
- if ( name.constructor == String )
+ if ( typeof name === "string" )
if ( value === undefined )
return this[0] && jQuery[ type || "attr" ]( this[0], name );
@@ -180,7 +180,7 @@
},
text: function( text ) {
- if ( typeof text != "object" && text != null )
+ if ( typeof text !== "object" && text != null )
return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
var ret = "";
@@ -323,7 +323,7 @@
},
not: function( selector ) {
- if ( selector.constructor == String )
+ if ( typeof selector === "string" )
// test special case where just one selector is passed in
if ( isSimple.test( selector ) )
return this.pushStack( jQuery.multiFilter( selector, this, true ) );
@@ -339,7 +339,7 @@
add: function( selector ) {
return this.pushStack( jQuery.unique( jQuery.merge(
this.get(),
- typeof selector == 'string' ?
+ typeof selector === "string" ?
jQuery( selector ) :
jQuery.makeArray( selector )
)));
@@ -400,7 +400,7 @@
return undefined;
}
- if( value.constructor == Number )
+ if ( typeof value === "number" )
value += '';
return this.each(function(){
@@ -550,7 +550,7 @@
var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
// Handle a deep copy situation
- if ( target.constructor == Boolean ) {
+ if ( typeof target === "boolean" ) {
deep = target;
target = arguments[1] || {};
// skip the boolean and the target
@@ -558,7 +558,7 @@
}
// Handle case when target is a string or something (possible in deep copy)
- if ( typeof target != "object" && typeof target != "function" )
+ if ( typeof target !== "object" && !jQuery.isFunction(target) )
target = {};
// extend jQuery itself if only one argument is passed
@@ -579,7 +579,7 @@
continue;
// Recurse if we're merging object values
- if ( deep && copy && typeof copy == "object" && !copy.nodeType )
+ if ( deep && copy && typeof copy === "object" && !copy.nodeType )
target[ name ] = jQuery.extend( deep,
// Never move original objects, clone them
src || ( copy.length != null ? [ ] : { } )
@@ -599,7 +599,8 @@
// exclude the following css properties to add px
exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
// cache defaultView
- defaultView = document.defaultView || {};
+ defaultView = document.defaultView || {},
+ toString = Object.prototype.toString;
jQuery.extend({
noConflict: function( deep ) {
@@ -611,19 +612,15 @@
return jQuery;
},
- // See test/unit/core.js for details concerning this function.
+ // See test/unit/core.js for details concerning isFunction.
// Since version 1.3, DOM methods and functions like alert
// aren't supported. They return false on IE (#2968).
-
- // Memory leaks appear in IE6 when applying instanceof
- // to the window, document or any other COM object (#3485)
- // http://ajaxian.com/archives/working-aroung-the-instanceof-memory-leak
- isFunction: function( fn ) {
- return !!fn && !!fn.hasOwnProperty && fn instanceof Function;
+ isFunction: function( obj ) {
+ return toString.call(obj) === "[object Function]";
},
-
- isArray: function( arr ){
- return !!arr && arr.constructor == Array;
+
+ isArray: function( obj ) {
+ return toString.call(obj) === "[object Array]";
},
// check if an element is in a (or is an) XML document
@@ -761,7 +758,7 @@
value = value.call( elem, i );
// Handle passing in a number to a CSS property
- return value && value.constructor == Number && type == "curCSS" && !exclude.test( name ) ?
+ return typeof value === "number" && type == "curCSS" && !exclude.test( name ) ?
value + "px" :
value;
},
@@ -946,19 +943,20 @@
clean: function( elems, context ) {
var ret = [];
context = context || document;
+
// !context.createElement fails in IE with an error but returns typeof 'object'
- if (typeof context.createElement == 'undefined')
+ if ( typeof context.createElement === "undefined" )
context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
jQuery.each(elems, function(i, elem){
- if ( typeof elem == 'number' )
+ if ( typeof elem === "number" )
elem += '';
if ( !elem )
return;
// Convert html string into DOM nodes
- if ( typeof elem == "string" ) {
+ if ( typeof elem === "string" ) {
// Fix "XHTML"-style tags in all browsers
elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ?
@@ -1139,7 +1137,7 @@
if( array != null ){
var i = array.length;
// The window, strings (and functions) also have 'length'
- if( i == null || typeof array == 'string' || jQuery.isFunction(array) || array.setInterval )
+ if( i == null || typeof array === "string" || jQuery.isFunction(array) || array.setInterval )
ret[0] = array;
else
while( i )
@@ -1369,7 +1367,7 @@
(this.length ? jQuery.css( this[0], type ) : null) :
// Set the width or height on the element (default to pixels if value is unitless)
- this.css( type, size.constructor == String ? size : size + "px" );
+ this.css( type, typeof size === "string" ? size : size + "px" );
};
});
Index: src/fx.js
===================================================================
--- src/fx.js (revision 5946)
+++ src/fx.js (working copy)
@@ -117,7 +117,7 @@
type = "fx";
}
- if ( !type || (typeof type == "string" && !fn) )
+ if ( !type || (typeof type === "string" && !fn) )
return queue( this[0], type );
return this.each(function(){
@@ -201,14 +201,14 @@
jQuery.extend({
speed: function(speed, easing, fn) {
- var opt = speed && speed.constructor == Object ? speed : {
+ var opt = typeof speed === "object" ? speed : {
complete: fn || !fn && easing ||
jQuery.isFunction( speed ) && speed,
duration: speed,
- easing: fn && easing || easing && easing.constructor != Function && easing
+ easing: fn && easing || jQuery.isFunction(easing) && easing
};
- opt.duration = jQuery.fx.off ? 0 : typeof opt.duration == 'number' ? opt.duration :
+ opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
jQuery.fx.speeds[opt.duration] || jQuery.fx.speeds._default;
// Queueing
Index: src/selector.js
===================================================================
--- src/selector.js (revision 5946)
+++ src/selector.js (working copy)
@@ -92,7 +92,7 @@
find: function( t, context ) {
// Quickly handle non-string expressions
- if ( typeof t != "string" )
+ if ( typeof t !== "string" )
return [ t ];
// check to make sure context is a DOM element or a document
@@ -214,7 +214,7 @@
// Do a quick check for the existence of the actual ID attribute
// to avoid selecting by the name attribute in IE
// also check to insure id is a string to avoid selecting an element with the name of 'id' inside a form
- if ( (jQuery.browser.msie||jQuery.browser.opera) && oid && typeof oid.id == "string" && oid.id != m[2] )
+ if ( (jQuery.browser.msie||jQuery.browser.opera) && oid && typeof oid.id === "string" && oid.id != m[2] )
oid = jQuery('[@id="'+m[2]+'"]', elem)[0];
// Do a quick check for node name (where applicable) so
@@ -391,10 +391,10 @@
// Otherwise, find the expression to execute
} else {
var fn = jQuery.expr[ m[1] ];
- if ( typeof fn == "object" )
+ if ( typeof fn === "object" )
fn = fn[ m[2] ];
- if ( typeof fn == "string" )
+ if ( typeof fn === "string" )
fn = eval("false||function(a,i){return " + fn + ";}");
// Execute it against the current filter
Index: src/event.js
===================================================================
--- src/event.js (revision 5946)
+++ src/event.js (working copy)
@@ -40,7 +40,7 @@
handle = jQuery.data(elem, "handle") || jQuery.data(elem, "handle", function(){
// Handle the second event of a trigger and when
// an event is called after a page has unloaded
- if ( typeof jQuery != "undefined" && !jQuery.event.triggered )
+ if ( typeof jQuery !== "undefined" && !jQuery.event.triggered )
return jQuery.event.handle.apply(arguments.callee.elem, arguments);
});
// Add elem as a property of the handle function
@@ -99,7 +99,7 @@
if ( events ) {
// Unbind all events for the element
- if ( types == undefined || (typeof types == "string" && types.charAt(0) == ".") )
+ if ( types == undefined || (typeof types === "string" && types.charAt(0) == ".") )
for ( var type in events )
this.remove( elem, type + (types || "") );
else {
Index: src/ajax.js
===================================================================
--- src/ajax.js (revision 5946)
+++ src/ajax.js (working copy)
@@ -3,7 +3,7 @@
_load: jQuery.fn.load,
load: function( url, params, callback ) {
- if ( typeof url != 'string' )
+ if ( typeof url !== "string" )
return this._load( url );
var off = url.indexOf(" ");
@@ -24,7 +24,7 @@
params = null;
// Otherwise, build a param string
- } else if( typeof params == 'object' ) {
+ } else if( typeof params === "object" ) {
params = jQuery.param( params );
type = "POST";
}
@@ -178,7 +178,7 @@
type = s.type.toUpperCase();
// convert data if not already a string
- if ( s.data && s.processData && typeof s.data != "string" )
+ if ( s.data && s.processData && typeof s.data !== "string" )
s.data = jQuery.param(s.data);
// Handle JSONP Parameter Callbacks
@@ -490,7 +490,7 @@
data = s.dataFilter( data, type );
// The filter can actually parse the response
- if( typeof data == 'string' ){
+ if( typeof data === "string" ){
// If the type is "script", eval it in global context
if ( type == "script" )