views:

38

answers:

2

Are there javascript libraries that provide forward compatibility with particular implementations? For example, such a library could provide features present in JavaScript 1.6 in a way that's portable across various browsers. It should take advantage of native support for that functionality when available.

Some of the frameworks like JQuery or Prototype provide features that are identical to features in newer versions of JS, but I'd like to both cut down on the size of the library I'm using and ensure full compliance with a standard or published version.

Do libraries such as this exist? Google and wikipedia don't have much to say on this topic.

+1  A: 

For example, such a library could provide features present in JavaScript 1.6 in a way that's portable across various browsers. It should take advantage of native support for that functionality when available.

This is pretty much what the frameworks do, and do well (even though most of the compatibility gaps they close are DOM and CSS related). I'm not aware of a general purpose framework with a focus on forward compatibility. Not sure whether something like that can exist at all, because looking at the Wikipedia article, many of the improvements in any version are constructs and behaviours that are very, very hard to simulate in an older version of the language (e.g. let, expression closures...)

Pekka
Good point. That occurred to me but I thought that JS 1.6 might not specify any such features. After [some more research](https://developer.mozilla.org/en/new_in_javascript_1.6), though, I realize I was wrong.
intuited
@intuit nice find! There are features that could probably be simulated in an older version (although I wouldn't want to be the one tasked with implementing it :D), but a number of things (Specifically, Array and String generics) couldn't.
Pekka
@Pekka: It looks like the `for each` syntax would definitely be unamenable to library implementation. To me it seems like Array and String generics could be implemented by overriding the various Array and String prototype methods.. but then I'm just really checking this out for the first time; I've always coded JS for 1.5 and avoided even learning the features of the newer versions.
intuited
A: 

It looks like there is such a library: the "JavaScript Standard Library" (JSL). It purports to provide as much JS 1.6 compatibility as possible for browsers supporting JS 1.2 or later.

I haven't used it, and am not sure of how well it works. The documentation is written in sketchy English; this could indicate a lack of widespread usage, since otherwise someone probably would have corrected it by now.

To add to the confusion, the site links to a JSL Revision, located on a different website, whose features list indicates that it provides a subset of the features listed at the main page.

The author has written some more about this library and about the general concepts involved in this blog post.

intuited