Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Core: Remove deprecated context and selector properties#2000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
dmethvin wants to merge2 commits intomasterfrom1908-context-selector
Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletionssrc/core.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -40,9 +40,6 @@ jQuery.fn = jQuery.prototype = {

constructor: jQuery,

// Start with an empty selector
selector: "",

// The default length of a jQuery object is 0
length: 0,

Expand DownExpand Up@@ -71,7 +68,6 @@ jQuery.fn = jQuery.prototype = {

// Add the old object onto the stack (as a reference)
ret.prevObject = this;
ret.context = this.context;

// Return the newly-formed element set
return ret;
Expand Down
12 changes: 2 additions & 10 deletionssrc/core/init.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -73,12 +73,9 @@ var rootjQuery,

if ( elem ) {
// Inject the element directly into the jQuery object
this.length = 1;
this[0] = elem;
this.length = 1;
Copy link
Member

Choose a reason for hiding this comment

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

We would save more bytes that way?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Seemed strange to set the length before the element. I pulled several of the changes from@gibson042 's older PR because they just seemed so right. 😄

Copy link
Member

Choose a reason for hiding this comment

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

:)

}

this.context = document;
this.selector = selector;
return this;
}

Expand All@@ -94,7 +91,7 @@ var rootjQuery,

// HANDLE: $(DOMElement)
} else if ( selector.nodeType ) {
this.context = this[0] = selector;
this[0] = selector;
this.length = 1;
return this;

Expand All@@ -107,11 +104,6 @@ var rootjQuery,
selector( jQuery );
}

if ( selector.selector !== undefined ) {
this.selector = selector.selector;
this.context = selector.context;
}

return jQuery.makeArray( selector, this );
};

Expand Down
5 changes: 1 addition & 4 deletionssrc/traversing/findFilter.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -72,10 +72,7 @@ jQuery.fn.extend({
jQuery.find( selector, self[ i ], ret );
}

// Needed because $( selector, context ) becomes $( context ).find( selector )
ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret );
ret.selector = this.selector ? this.selector + " " + selector : selector;
return ret;
return this.pushStack( len > 1 ? jQuery.unique( ret ) : ret );
},
filter: function( selector ) {
return this.pushStack( winnow(this, selector || [], false) );
Expand Down
45 changes: 1 addition & 44 deletionstest/unit/core.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -57,7 +57,7 @@ test("jQuery()", function() {
equal( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" );
equal( jQuery(null).length, 0, "jQuery(null) === jQuery([])" );
equal( jQuery("").length, 0, "jQuery('') === jQuery([])" );
equal( jQuery(obj).selector, "div", "jQuery(jQueryObj) == jQueryObj" );
deepEqual( jQuery(obj).get(), obj.get(), "jQuery(jQueryObj) == jQueryObj" );

// Invalid #id goes to Sizzle which will throw an error (gh-1682)
try {
Expand DownExpand Up@@ -156,49 +156,6 @@ test("jQuery(selector, context)", function() {
deepEqual( jQuery("div p", jQuery("#qunit-fixture")).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
});

test( "selector state", function() {
expect( 18 );

var test;

test = jQuery( undefined );
equal( test.selector, "", "Empty jQuery Selector" );
equal( test.context, undefined, "Empty jQuery Context" );

test = jQuery( document );
equal( test.selector, "", "Document Selector" );
equal( test.context, document, "Document Context" );

test = jQuery( document.body );
equal( test.selector, "", "Body Selector" );
equal( test.context, document.body, "Body Context" );

test = jQuery("#qunit-fixture");
equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
equal( test.context, document, "#qunit-fixture Context" );

test = jQuery("#notfoundnono");
equal( test.selector, "#notfoundnono", "#notfoundnono Selector" );
equal( test.context, document, "#notfoundnono Context" );

test = jQuery( "#qunit-fixture", document );
equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
equal( test.context, document, "#qunit-fixture Context" );

test = jQuery( "#qunit-fixture", document.body );
equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
equal( test.context, document.body, "#qunit-fixture Context" );

// Test cloning
test = jQuery( test );
equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
equal( test.context, document.body, "#qunit-fixture Context" );

test = jQuery( document.body ).find("#qunit-fixture");
equal( test.selector, "#qunit-fixture", "#qunit-fixture find Selector" );
equal( test.context, document.body, "#qunit-fixture find Context" );
});

test( "globalEval", function() {
expect( 3 );
Globals.register("globalEvalTest");
Expand Down
6 changes: 3 additions & 3 deletionstest/unit/offset.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -462,9 +462,9 @@ testIframe("offset/body", "body", function( $ ) {
test("chaining", function() {
expect(3);
var coords = { "top": 1, "left": 1 };
equal( jQuery("#absolute-1").offset(coords).selector, "#absolute-1", "offset(coords) returns jQuery object" );
equal( jQuery("#non-existent").offset(coords).selector, "#non-existent", "offset(coords) with empty jQuery set returns jQuery object" );
equal( jQuery("#absolute-1").offset(undefined).selector, "#absolute-1", "offset(undefined) returns jQuery object (#5571)" );
equal( jQuery("#absolute-1").offset(coords).jquery, jQuery.fn.jquery, "offset(coords) returns jQuery object" );
Copy link
Member

Choose a reason for hiding this comment

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

Always wondered why this property was named "jquery", not "version"

Copy link
Member

Choose a reason for hiding this comment

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

It's killing two birds with one stone: thepresence of the property identifies an object as a jQuery collection as opposed to Array/NodeList/Prototype/Zepto/etc., and the value specifies which version.

Copy link
Member

Choose a reason for hiding this comment

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

It's killing two birds with one stone

Yeah! Or "a bird in the hand is worth two in the bush"

This property indeed serve for two complitly different things, but i don't think that's good, i think these should be exposed explicitly then otherwise. Besides, i'm not sure that was an original intent.

the presence of the property identifies an object as a jQuery

This could always be done by other means, like:

functiontest(){}newtest().constructor.name// test// i.e. we could dofunctionjQuery(){}jQuery.prototype.constructor=jQuery;$().constructor.name// "jQuery"

Or other countless ways to do it. Not saying we should do something about it, it might be too late, like with$.each vs $.map callback arguments case :-(

Copy link
Member

Choose a reason for hiding this comment

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

Yea, it's too late.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Until I looked at the old PR, I had just planned to see if the.selector property was present but the change by@gibson042 seemed like a slightly better assertion.

I guess.version was avoided since it's a pretty common name. You wouldn't thinksomeobject.fn.version would be that ambiguous but it's also available viasomeobject.prototype.version so maybe that caused concern.

Copy link
Member

Choose a reason for hiding this comment

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

Yea, it's too late.

Isn't that frustrating? We can't improve something because people are dependent upon it.

I guess .version was avoided since it's a pretty common name.

If i would do it today, i would called it "version" and provided other ways to identify jquery object

Copy link
Member

Choose a reason for hiding this comment

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

This property indeed serve for two complitly different things, but i don't think that's good, i think these should be exposed explicitly then otherwise.

The purposes aren't completely different; they're analogous tonodeType checks in that both properties are considered to have a universal meaning regardless of where they appear.jquery specifies the version of jQuery used to construct a collection, which—since it must beundefined for objects that arenot jQuery collections—can be cast as a boolean for type checking, just like castingnodeType to boolean checks for DOM nodes. That said, though, there might well have been a better choice for the name, but it's definitely too late to change.

equal( jQuery("#non-existent").offset(coords).jquery, jQuery.fn.jquery, "offset(coords) with empty jQuery set returns jQuery object" );
equal( jQuery("#absolute-1").offset(undefined).jquery, jQuery.fn.jquery, "offset(undefined) returns jQuery object (#5571)" );
});

test("offsetParent", function(){
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp