jquery core: $() -> $(document) and $(undefined) -> $([]). Removed a duplicated block.
This commit is contained in:
parent
e45b41602f
commit
3a80de1c7a
2 changed files with 13 additions and 13 deletions
|
@ -18,7 +18,7 @@ var window = this,
|
||||||
|
|
||||||
jQuery = window.jQuery = window.$ = function( selector, context ) {
|
jQuery = window.jQuery = window.$ = function( selector, context ) {
|
||||||
// The jQuery object is actually just the init constructor 'enhanced'
|
// The jQuery object is actually just the init constructor 'enhanced'
|
||||||
return selector === undefined ?
|
return arguments.length === 0 ?
|
||||||
rootjQuery :
|
rootjQuery :
|
||||||
new jQuery.fn.init( selector, context );
|
new jQuery.fn.init( selector, context );
|
||||||
},
|
},
|
||||||
|
@ -36,12 +36,6 @@ var window = this,
|
||||||
// Save a reference to the core toString method
|
// Save a reference to the core toString method
|
||||||
toString = Object.prototype.toString;
|
toString = Object.prototype.toString;
|
||||||
|
|
||||||
// Define the main jQuery method
|
|
||||||
jQuery = window.jQuery = window.$ = function( selector, context ) {
|
|
||||||
// The jQuery object is actually just the init constructor 'enhanced'
|
|
||||||
return new jQuery.fn.init( selector, context );
|
|
||||||
};
|
|
||||||
|
|
||||||
jQuery.fn = jQuery.prototype = {
|
jQuery.fn = jQuery.prototype = {
|
||||||
init: function( selector, context ) {
|
init: function( selector, context ) {
|
||||||
var match, elem, ret;
|
var match, elem, ret;
|
||||||
|
|
|
@ -12,8 +12,19 @@ test("Basic requirements", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("jQuery()", function() {
|
test("jQuery()", function() {
|
||||||
expect(8);
|
expect(11);
|
||||||
|
|
||||||
|
// Basic constructor's behavior
|
||||||
|
|
||||||
|
equals( jQuery().length, 1, "jQuery() === jQuery(document)" );
|
||||||
|
equals( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" );
|
||||||
|
equals( jQuery(null).length, 0, "jQuery(null) === jQuery([])" );
|
||||||
|
equals( jQuery("").length, 0, "jQuery('') === jQuery([])" );
|
||||||
|
|
||||||
|
// can actually yield more than one, when iframes are included, the window is an array as well
|
||||||
|
equals( 1, jQuery(window).length, "Correct number of elements generated for jQuery(window)" );
|
||||||
|
|
||||||
|
|
||||||
var main = jQuery("#main");
|
var main = jQuery("#main");
|
||||||
isSet( jQuery("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
|
isSet( jQuery("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
|
||||||
|
|
||||||
|
@ -42,11 +53,6 @@ test("jQuery()", function() {
|
||||||
var div = jQuery("<div/><hr/><code/><b/>");
|
var div = jQuery("<div/><hr/><code/><b/>");
|
||||||
equals( div.length, 4, "Correct number of elements generated for div hr code b" );
|
equals( div.length, 4, "Correct number of elements generated for div hr code b" );
|
||||||
|
|
||||||
// can actually yield more than one, when iframes are included, the window is an array as well
|
|
||||||
equals( jQuery(window).length, 1, "Correct number of elements generated for window" );
|
|
||||||
|
|
||||||
equals( jQuery(document).length, 1, "Correct number of elements generated for document" );
|
|
||||||
|
|
||||||
equals( jQuery([1,2,3]).get(1), 2, "Test passing an array to the factory" );
|
equals( jQuery([1,2,3]).get(1), 2, "Test passing an array to the factory" );
|
||||||
|
|
||||||
equals( jQuery(document.body).get(0), jQuery('body').get(0), "Test passing an html node to the factory" );
|
equals( jQuery(document.body).get(0), jQuery('body').get(0), "Test passing an html node to the factory" );
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue