admin管理员组

文章数量:1323342

I know some Javascript, but just realized I know very little about cross-browser issues. Nasty little things like the this object in event callbacks in IE (as in xhr.onreadystatechange = function () { ... }) not referring to the object the function is applied to, but instead to window, which is not exactly useful.

There's an impressive and prehensive-looking list of differences here on SO.

Is there also a library that covers these nasty cross-browser issues without selling you a whole lifestyle plus round corners with slide effects? I know jQuery is great (and modular, I know, UI ing as an extra; and I bet others are great, too), but I'm looking for something lean, closer to the roots. Just doing the minimum and eliminating the nastiness. Doesn't have to wrap the DOM in sugar.

Update

Thanks everybody for your suggestions. I'm going to take a look at MyLib, microJS, Ender, and Sizzle. GWT, while certainly being cross-browser, is not, I think, a lightweight approach, but definitely an interesting one.

I know some Javascript, but just realized I know very little about cross-browser issues. Nasty little things like the this object in event callbacks in IE (as in xhr.onreadystatechange = function () { ... }) not referring to the object the function is applied to, but instead to window, which is not exactly useful.

There's an impressive and prehensive-looking list of differences here on SO.

Is there also a library that covers these nasty cross-browser issues without selling you a whole lifestyle plus round corners with slide effects? I know jQuery is great (and modular, I know, UI ing as an extra; and I bet others are great, too), but I'm looking for something lean, closer to the roots. Just doing the minimum and eliminating the nastiness. Doesn't have to wrap the DOM in sugar.

Update

Thanks everybody for your suggestions. I'm going to take a look at MyLib, microJS, Ender, and Sizzle. GWT, while certainly being cross-browser, is not, I think, a lightweight approach, but definitely an interesting one.

Share Improve this question edited May 23, 2017 at 12:06 CommunityBot 11 silver badge asked Aug 2, 2011 at 23:27 LumiLumi 15.3k9 gold badges64 silver badges93 bronze badges 9
  • What you want most is a highly supported and documented library because without either of those, you will have trouble using it and it's usefulness will fade over time. IMO, that is going to lead you to the market leaders such as jQuery, YUI3 and a few others even though they may offer more than you think you need. There are caching reasons for using a popular library loaded from a popular CDN too that will help your page load quicker. – jfriend00 Commented Aug 2, 2011 at 23:34
  • @Lumi Could you elaborate why jQuery is not close enough to the roots for you? It looks like it's as close as it gets to me... – Šime Vidas Commented Aug 2, 2011 at 23:49
  • 1 @SimeVidas jQuery is a large bloated library. You only use 20% of it. – Raynos Commented Aug 2, 2011 at 23:51
  • @Raynos But since the dependencies are linear, cant you go into github and essentially cut off the dead weight by only including code up to module X? – Moses Commented Aug 2, 2011 at 23:58
  • 1 @Moses no. jQuery is not modular. It's all, sizzle or nothing – Raynos Commented Aug 2, 2011 at 23:58
 |  Show 4 more ments

6 Answers 6

Reset to default 3

jQuery is not modular - it's all or nothing. If you want a solid, cross browser library that you can trim to the minimum you require, it's hard to go past MyLibrary: http://www.cinsoft/mylib.html.

The name "MyLibrary" means that when you download and customise it, it bees your library.

It is absolutely solid, fast and extremely modular. You can use just the bits you want and remove anything unnecessary.

BTW, many libraries like jQuery aren't really "cross browser", they are multi–browser — they have a limited set of browsers that they support and don't care much about the rest. On the other hand, MyLibrary is written to be genuinely cross–browser. It also provides excellent feature detection shortcuts so you can easily write robust code with fallback.

What do you want?

Just check microJS and download the libraries you want.

As mentioned already you can use Ender to bundle them

"Minimal cross-browser Javascript library" + "I'm looking for something lean, closer to the roots"

I immediately thought of MyLib.
You can even build your own custom version using this online tool.

I think you should have a look at Ender By Dustian Diaz and Jacob Thornton working at Twitter.

Ender is not a JavaScript library in the traditional sense. So don't rush out and try to replace jQuery or MooTools with Ender... It just wouldn't work.... But! you can build a library from Ender which will. And you should. right now.

That's because: Ender is an open, powerful, micro-to-macro API for posing your own custom JavaScript library; it wraps up application agnostic, independent modules into a slick, intuitive, and familiar interface so you don't have to.

Well the problem with this in JavaScript is that it can be a bit confusing to people which are not accustomed to the fact that it always gets a contextual value or in other words it will always point to the object which is in the current context of the executing code.

In case of some events, intervals etc. its absolutely normal that this points to window because a LOT (perhaps too much) of properties in JavaScript are attached to the window object.

As for which JS library to use for your work...Well if you don't want to use jQuery as a whole there is always the most important part of it which handles selection of objects inside DOM and is pretty much important for cross browser patibility.

Its called Sizzle and can be found here. It doesn't offer fancy stuff like jQuery does but it is small and offers a great cross-browser way to select stuff on pages.

You can look at GWT.. but it does sell you a lifestyle as well - a Java dev environment. But that also brings in a debugger, a proper IDE, easier OO, it piles to optimized cross-browser javascript etc. And you can always mix and match native JavaScript where you see fit.

本文标签: Wanted Minimal crossbrowser Javascript libraryStack Overflow