Reputation: 15264
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 comprehensive-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 coming 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.
Upvotes: 4
Views: 1568
Reputation: 15136
"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.
Upvotes: 3
Reputation: 147343
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.net/mylib.html.
The name "MyLibrary" means that when you download and customise it, it becomes 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.
Upvotes: 3
Reputation: 3265
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 compiles to optimized cross-browser javascript etc. And you can always mix and match native JavaScript where you see fit.
Upvotes: -1
Reputation: 169373
What do you want?
Just check microJS and download the libraries you want.
As mentioned already you can use Ender to bundle them
Upvotes: 3
Reputation:
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 compatibility.
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.
Upvotes: 0
Reputation: 61771
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 composing 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.
Upvotes: 1