Skip to content
Permalink
Browse files
Switched jQuery() to represent jQuery([]) instead of jQuery(document).
  • Loading branch information
jeresig committed Dec 10, 2009
1 parent b846ad4 commit 04524287d3e0112deae570ff9247c734833431bb
Showing 2 changed files with 2 additions and 4 deletions.
@@ -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
@@ -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([])" );

8 comments on commit 0452428

@ajpiano
Copy link
Member

@ajpiano ajpiano commented on 0452428 Dec 14, 2009

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

@padolsey padolsey commented on 0452428 Dec 14, 2009

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

@padolsey padolsey commented on 0452428 Dec 14, 2009

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

@padolsey padolsey commented on 0452428 Dec 14, 2009

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

@dmethvin dmethvin commented on 0452428 Dec 15, 2009

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

@adardesign adardesign 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.

@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

@paulirish paulirish commented on 0452428 Jan 18, 2010

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.