Skip to content
Permalink
Browse files

No reason to expose the temporary _load method.

  • Loading branch information
jeresig committed Feb 11, 2010
1 parent d3d497f commit 639f4931b0409a8eb83aaf89a03b6b52f674663e
Showing with 5 additions and 5 deletions.
  1. +5 −5 src/ajax.js
@@ -6,15 +6,15 @@ var jsc = now(),
rquery = /\?/,
rts = /(\?|&)_=.*?(&|$)/,
rurl = /^(\w+:)?\/\/([^\/?#]+)/,
r20 = /%20/g;
r20 = /%20/g,

jQuery.fn.extend({
// Keep a copy of the old load
_load: jQuery.fn.load,
// Keep a copy of the old load method
_load = jQuery.fn.load;

jQuery.fn.extend({
load: function( url, params, callback ) {
if ( typeof url !== "string" ) {
return this._load( url );
return _load.call( this, url );

// Don't do a request if no elements are being requested
} else if ( !this.length ) {

5 comments on commit 639f493

@GarrettS

This comment has been minimized.

Copy link

GarrettS replied Feb 18, 2010

Is the "old load method" defined anywhere? I don't see it. It looks like if there is no old "load" method, and the first argument is a string, a TypeError should occur (as the result of performing a call operation on an undefined value).

Have you considered moving some of the method to a separate function, e.g. from:

// Request the remote document
// [...]

to:


requestRemoteDocument( /* context args */ );

I also see that jQuery.ajax is a very long method, with a lot of conditional logic around the dataType.

@GarrettS

This comment has been minimized.

Copy link

GarrettS replied Feb 18, 2010

sorry, should be:

...if there is no "old load" method, and the first argument is not a string...

@jeresig

This comment has been minimized.

Copy link
Member Author

jeresig replied Feb 18, 2010

The "old load method" is in event.js, which is always compiled in before ajax.js.

@GarrettS

This comment has been minimized.

Copy link

GarrettS replied Feb 18, 2010

I see: This is a workaround to an internal name collision of load. The workaround/solution you've employed seems to be creating very tight coupling between ajax.js, event.js, and build order.

The load method in ajax.js expects that there is a load method defined elsewhere (it is in event.js), that that other load method accepts non-string values and that it does not accept string values (because ajax.js' load takes that case). This is essentially a mutual exclusion between parameter type between two same-named methods of two modules.

The problems related to the name collision can be avoided by renaming ajax.js' load method to something that does not conflict, such as loadURL , makeRequest, etc. Why not do that?

@jeresig

This comment has been minimized.

Copy link
Member Author

jeresig replied Feb 18, 2010

Well, we've done it this way for almost 4 years now. The decision to overload the functionality of .load() to both event and ajax was made fairly early on. Much in the same way we overload .attr() (and don't have getAttr and setAttr).

Please sign in to comment.
You can’t perform that action at this time.