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 with 2 additions and 4 deletions.
  1. +1 −3 src/core.js
  2. +1 −1 test/unit/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
@@ -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

This comment has been minimized.

Copy link
Member

@ajpiano ajpiano replied Dec 14, 2009

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

This comment has been minimized.

Copy link
Contributor

@padolsey padolsey replied Dec 14, 2009

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

This comment has been minimized.

Copy link
Contributor

@padolsey padolsey replied Dec 14, 2009

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

@padolsey

This comment has been minimized.

Copy link
Contributor

@padolsey padolsey replied Dec 14, 2009

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

@dmethvin

This comment has been minimized.

Copy link
Member

@dmethvin dmethvin replied Dec 15, 2009

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

This comment has been minimized.

Copy link

@adardesign adardesign replied Jan 17, 2010

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

@tj

This comment has been minimized.

Copy link
Contributor

@tj tj replied Jan 17, 2010

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

@paulirish

This comment has been minimized.

Copy link
Member

@paulirish paulirish replied Jan 18, 2010

@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.
You can’t perform that action at this time.