Skip to content

Commit

Permalink
Switched jQuery() to represent jQuery([]) instead of jQuery(document).
Browse files Browse the repository at this point in the history
  • Loading branch information
jeresig committed Dec 10, 2009
1 parent b846ad4 commit 0452428
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/core.js
@@ -1,9 +1,7 @@
// Define a local copy of jQuery
var jQuery = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return arguments.length === 0 ?
rootjQuery :
new jQuery.fn.init( selector, context );
return new jQuery.fn.init( selector, context );
},

// Map over jQuery in case of overwrite
Expand Down
2 changes: 1 addition & 1 deletion test/unit/core.js
Expand Up @@ -16,7 +16,7 @@ test("jQuery()", function() {

// Basic constructor's behavior

equals( jQuery().length, 1, "jQuery() === jQuery(document)" );
equals( jQuery().length, 0, "jQuery() === jQuery([])" );
equals( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" );
equals( jQuery(null).length, 0, "jQuery(null) === jQuery([])" );
equals( jQuery("").length, 0, "jQuery('') === jQuery([])" );
Expand Down

8 comments on commit 0452428

@ajpiano
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a great idea, but it's going to screw over a LOT of people who followed bad jQuery tutorials online that all seem to love recommending $() as a shortcut to $(document).

@padolsey
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yowzer! This is going to break a lot of code: http://www.google.com/codesearch?hl=en&lr=&q=\$\(\)\.ready&sbtn=Search

I agree with ajpiano though; definitely a good idea!

@padolsey
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops. That link's broken. This works - http://bit.ly/69rX6h

@padolsey
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh, nevermind, seems that jQuery.fn.ready binds the ready function regardless of the collection.

@dmethvin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since .ready() still works it doesn't seem too bad. Using a modified search of $(). on Google Code I found these that may need changing:

jqDnR
BlockUI
jrails
svg-editor
jsSpeedTester

It would be great to see this change happen but maybe it needs to go through a deprecation phase?

@adardesign
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ajpiano $(document).ready(function(){
// this is much clearer, more readable!
})

@tj
Copy link
Contributor

@tj tj commented on 0452428 Jan 17, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$(function(){ ... }) is still $(document).ready() I hope

@paulirish
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@visionmedia

but of course. no change there.

also this is an old commit. $().ready(function(){ .. will actually work in 1.4, but its deprecated
$().bind/trigger do NOT work in 1.4 however

Please sign in to comment.