Bug Tracker

Opened 10 years ago

Closed 8 years ago

#5882 closed enhancement (wontfix)

jQuery.fn.jquery -- version string property change

Reported by: shadedecho Owned by: shadedecho
Priority: low Milestone:
Component: core Version: 1.4
Keywords: version $.fn.jquery Cc: SlexAxton
Blocked by: Blocking:

Description

Firstly, it would be really nice if this property was documented.

Secondly, it would be nice if either the property were numeric (with the parts separated, like in an array or object), or better, if there was an easy built-in utility for comparing version numbers. Like, asking the question, "is this jQuery at least 1.3.1", etc.

I know many people have written various different ones, but it'd be great if that was just included as a little snippet in with jQuery core so that the version string was actually useful instead of a hindrance to information. In other words, my goal is usually not "is the version exactly x.x.x", my goal is usually "is the version at least x.x.x" and that's harder to do with just this string property as-is.

Specifically, I'm thinking this type of functionality could be helpful to plugin authors, like not just the typical "if (jquery) { .... }" kind of wrapper, but more specifically, if the plugin needs and only works in a specific jquery version or versions, an easy way for that question to be baked into the plugin code's wrapper logic.

Change History (5)

comment:1 Changed 9 years ago by dmethvin

Component: unfiledcore

comment:2 Changed 9 years ago by Rick Waldron

Owner: set to shadedecho
Status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a jsFiddle that outlines practical use cases for your enhancement request.

comment:3 Changed 9 years ago by shadedecho

Status: pendingnew

The use-case I was facing at the time of this filing was: creating a "widget" that can be arbitrarily included in any existing web page (drop-in with a script tag) that creates some content, like a twitter widget or something. The widget wants to use jQuery, so it first tests for the prior existence of jQuery on the page. If it finds a jQuery object, it then needs to make sure it's a relatively new (and thus less buggy) version of jQuery. If jQuery is not found, or it's not new enough (at least 1.3), then instead just re-load a new copy of latest jQuery to the page, and then use noConflict() to roll back the page's version to what it was before, and store the new (now sandboxed) updated jQuery just loaded for private use by the widget.

Obviously, the part that's more awkward/difficult is in comparing the jQuery version of any existing found jQuery instance, as it's just a (undocumented) string property, that must be broken down and numerically compared.

If it were an array where the parts were numbers, this comparison would be much easier. But even better, if there was a simple comparison function like "isAtLeastVersion(...)", then the question being asked (is it at least some X.Y version) would be easy to check against.

BTW, there was quite a bit of discussion about this idea on this jQuery github commit awhile back:

http://github.com/jquery/jquery/commit/7e6b20e2e813e774ce970d17215260d54bf15cd7

Not really sure anything ever came of it though.

comment:4 Changed 9 years ago by SlexAxton

Cc: SlexAxton added
Keywords: version $.fn.jquery added
Milestone: 1.4.11.5
Priority: triviallow
Status: newopen

I think minimally documentation would be worthwhile, for sure. I think it's worth some discussion once some of the other stuff comes up to see how deep we'd want to enhance the version numbers, etc. On the one hand, it can be really handy, and on the other hand, it has the potential to become a similar problem to browser UA sniffing, etc.

I'll push it through as a very worthwhile enhancement to discuss, and include you when that discussion eventually occurs.

Thanks!

comment:5 Changed 8 years ago by john

Resolution: wontfix
Status: openclosed

I'm not sure if this is really something that we want to tackle, explicitly (and if we do, it would certainly be part of a larger dependency management technique, I'm sure).

For right now doing simple testing like: parseFloat( foo.jquery ) >= 1.5 would work fine.

Note: See TracTickets for help on using tickets.