Bug Tracker

Modify

Ticket #7224 (closed enhancement: wontfix)

Opened 3 years ago

Last modified 2 years ago

Have jQuery.type return "jQuery" for jQuery objects

Reported by: T.J. Crowder Owned by: rwaldron
Priority: low Milestone: 1.5
Component: core Version: 1.4.3
Keywords: needsreview Cc:
Blocking: Blocked by:

Description

The new jQuery.type function is great! Would like to see an enhancement to it: Return "jQuery" for jQuery instances. This comes out of  this question on StackOverflow, in which the OP wanted to know how to reliably tell whether a given object was a jQuery instance or not. Nick Craver suggested looking for whether it has a .jquery property on it, but as that property is undocumented, I lean away from it. jQuery.type seems like an excellent way to document a means of doing this test.

Change History

comment:1 Changed 3 years ago by T.J. Crowder

See also ticket #7200, which is a ticket Nick created for documenting the .jquery property.

comment:2 follow-up: ↓ 3 Changed 3 years ago by snover

  • Keywords needsreview added

Bikeshed/feature creep. Marking for review.

comment:3 in reply to: ↑ 2 Changed 3 years ago by T.J. Crowder

Replying to snover:

Bikeshed/feature creep. Marking for review.

Not all refinement suggestions are bikeshedding.

comment:4 Changed 3 years ago by snover

  • Milestone changed from 1.4.4 to 1.5

Retarget all enhancements/features to next major version.

comment:5 Changed 3 years ago by rwaldron

  • Priority changed from undecided to low
  • Component changed from unfiled to core

comment:6 Changed 2 years ago by dmethvin

  • Keywords needsdocs added

Core currently uses .jquery in a few places, so perhaps we should document it since it's been that way for years? If it makes sense to distinguish a jQuery object in jQuery.type great.

comment:7 Changed 2 years ago by dmethvin

Related to #7200 .

comment:8 Changed 2 years ago by dmethvin

  • Status changed from new to open

comment:9 Changed 2 years ago by rwaldron

#7815 is a duplicate of this ticket.

comment:10 Changed 2 years ago by rwaldron

  • Owner set to rwaldron
  • Status changed from open to assigned

comment:11 Changed 2 years ago by rwaldron

Adds a condition to jQuery.type that checks for the existence of a jquery property on the object being tested, and whether or not that property's value is the same as jQuery.fn.jquery (helps avoid false positives)

 https://github.com/jquery/jquery/pull/151

comment:12 Changed 2 years ago by snover

I still don’t see any reason for this. If someone wants to know if an object is a jQuery object, the standard mechanism for performing such a test is to inspect whether or not a jquery property exists, and that’s not likely to change any time soon since it is used very heavily internally and has been promoted as the de facto mechanism for testing.

Making this change only guarantees that people will end up assuming that its return value is a guarantee, when internally we are just doing the exact same thing. Additionally, this mechanism is intended only to expose the class type of JavaScript natives, not user-created classes, and I think it’s at worst dangerous, at best needless to embellish it with special magic for jQuery just because we can.

Last edited 2 years ago by snover (previous) (diff)

comment:13 follow-up: ↓ 14 Changed 2 years ago by rwaldron

  • Status changed from assigned to closed
  • Resolution set to worksforme

comment:14 in reply to: ↑ 13 Changed 2 years ago by T.J. Crowder

Replying to rwaldron: I don't know much about Trac, but I'm not following "worksforme". Did you mean "wontfix" (in deference to @snover's view)? Or "fixed" (by your pull request)?

comment:15 follow-up: ↓ 16 Changed 2 years ago by dmethvin

I think the "worksforme" here is intended to mean that there is a good solution available (check for the .jquery property) so we don't need to add anything to .type().

Like snover said, .type() currently returns Javascript types. Also, like many utility functions in jQuery it was created for an internal core code need. Core doesn't get any benefit from this addition.

We still need to document the .jquery property per #7200.

comment:16 in reply to: ↑ 15 Changed 2 years ago by T.J. Crowder

Replying to dmethvin:

I think the "worksforme" here is intended to mean that there is a good solution available...

Okay. To me it's a "wontfix". The thing doesn't do what was requested; "worksforme" in every bug tracker I've dealt with means, basically, the report was erroneous or we haven't managed to replicate it. Doesn't really matter, but seems odd.

Agreed about #7200, easy enough to create one's own type knowing that that's not going to disappear.

comment:17 Changed 2 years ago by rwaldron

  • Status changed from closed to reopened
  • Resolution worksforme deleted

comment:18 Changed 2 years ago by rwaldron

  • Status changed from reopened to closed
  • Resolution set to wontfix

Bikeshedding.

comment:19 Changed 2 years ago by kswedberg

  • Keywords needsdocs removed

documentation was added 2/11/2011

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.