base2.DOM is my kind of JavaScript library

While reading Dean Edwards’ post Yet Another JavaScript Library Without Documentation I felt something connect inside my brain. That was a really nice feeling ;-).

The JavaScript library Dean talks about is his own base2.DOM, which is the first library I’ve looked at that feels completely right to me. It feels right because:

  • It uses standard DOM properties and methods
  • It lets JavaScript look like JavaScript
  • It doesn’t use the weird (but popular) “$”
  • It doesn’t contain any visual effects

What it does is make all supported browsers behave the same way when using standard JavaScript, and implement stuff like the Selectors API and getElementsByClassName().

Great stuff, Dean. Thanks for creating this.

Posted on April 3, 2007 in JavaScript, Quicklinks

Comments

  1. For those interested, Dean has updated base2.DOM to Google Code http://dean.edwards.name/weblog/2007/04/base2-google/.

  2. I think the overall idea behind Dean’s Base2.DOM is great. Let’s make all browsers behave the same by implementing missing features, fixing broken ones and implementing new features just like standards say they will.

    But I soon noticed the code was 20Ko, packed. Wow, it’s big. Finally I tried to look at the code. I only tried, thought, because I just couldn’t understand a single bit of it: it’s damn too complicated! I’d wish for it to be as clean and nice to read as mootools’ code…

    I repeat myself: the idea is great and I think it’s what should be achieved, just as you think; but I’m sure the same could be achieved with less and simpler code.

    Note: the “$” function isn’t that weird and is just some shortcut to “document.getElementById” — adding a few enhancements to the element on the way.

  3. April 4, 2007 by Roger Johansson (Author comment)

    Benson: Thanks for mentioning that - I forgot to check Dean’s site for updates before posting this.

    JMG: Yeah 20 KB is a bit heavy, I agree.

    The “$” function feels very weird to me. I think it is one of the reasons I find JS that relies on for instance jQuery to be very hard to understand.

  4. Awesome, innit? I like the idea cos I get the impression that my years of trying to learn JavaScript properly won’t be wasted, and I won’t have to learn a bunch of library-specific stuff.

  5. Idea is OK if you are into standards, but if you care about getting your job done with minimum of understandable and maintainable code than base2.DOM can’t compete with other libraries.

    There is an example in the comments posted as a bug demonstration. It uses 19 lines of code to attach two event handlers when document gets loaded. I reproduced the same functionality with 7 lines of properly formated code. Code is cleaner, shorter and does not have stuff like ‘DOMContentLoaded’.

  6. @JMG - I tried my best to make the code readable but I accept that it might be difficult to understand for some. A lot of the complexity is for the parsing of CSS selectors. It’s fast but it’s ugly.

    It’s funny that you compare it unfavourably to mootools as I think mootools is the most similar in coding style to base2. Oh well. :-)

  7. April 4, 2007 by Michael Thompson

    I won’t waste time trying to sway anyone’s opinion about the “$” selector, library features, blah blah blah…

    Some of my fellow web professionals are starting to sound like overzealous geriatrics: “We’ve always done it this way, and we ain’t a-changin’!” Always insisting on writing helpers and the like from scratch — making minuscule optimizations unique to whatever project the code is for — is sadistic.

    It’s interesting to me that most of the support for this library is coming from sticklers who say things like, “my years of trying to learn JavaScript properly won’t be wasted.”

    This is a bloated library with minimal functionality and very few time-saving features.

    Long live jQuery (aka ECMA-Ruby). :P

  8. @Michael - I love jQuery but I’m really starting to dislike its users. Why do you have to make everything into a competition? There is plenty of room for all sorts of JavaScript libraries to do all sorts of things. This library does one thing: standards. Some people, like Roger, prefer to work with standards.

    If you have been developing in JavaScript for a few years and don’t want to learn a new API then you might prefer this library. If you are new to JavaScript then I would happily recommend jQuery over my own library for simple to moderately complex scripting.

    One other thing to consider:

    Create a page and script it with jQuery. Come back in 2 years. Does the site still work? In five years? Ten?

    Now script it with standard DOM methods. Come back in ten years and it will still be working.

  9. @Dean - As a user of jQuery (and a member of the project team), I’m disappointed to hear about your negative experiences with jQuery users.

    You’re absolutely right about their being “plenty of room” for all sort of JavaScript libraries, and I’m really looking forward to examining yours and possibly using it for a project. I’m already a big fan of your JavaScript packer and admire the work you’ve done across the board.

    @Roger, keep the thought-provoking and informative entries coming! Your blog is one of the very few for which I find compelling content in every post. I may not always agree with your conclusions (though usually I do), but I always appreciate your sound reasoning and analysis.

    Cheers to both of you!

  10. @Dean: Karl summed it pretty well and rest assured that nobody on the jQuery project team condones or supports Michael’s comments. Hopefully you won’t allow a few folks to sully your opinion of a truly great community. If you ever have any issues, please don’t hesitate to contact me, Karl or John Resig directly. We truly value your contributions to the development community and appreciate your support of jQuery.

  11. @Karl/Rey - thanks guys. I was probably being a little touchy if truth be told. And for the record:

    http://dean.edwards.name/weblog/2007/03/rules/#comment82010

  12. @Dean…

    You say that if you code a page according to DOM standards, come back in 2 years, 5 years, etc. “will the page still work”? You’re making assumptions that the standards won’t have changed in that time. That’s just as likely to happen as something written in jQuery.

    I’m not bashing your library at all…just pointing out. I respect the work you’ve done online and am just happy to be the recipient of all of these libraries which make my job easier (and more fun).

  13. You say that if you code a page according to DOM standards, come back in 2 years, 5 years, etc. “will the page still work”? You’re making assumptions that the standards won’t have changed in that time. Standards not change they evolve. Modern browsers still understand DOM level 1, for example. Same for HTML, same for CSS.

  14. You say that if you code a page according to DOM standards, come back in 2 years, 5 years, etc. “will the page still work”? You’re making assumptions that the standards won’t have changed in that time.

    Standards not change they evolve.

    Modern browsers still understand DOM level 1, for example. Same for HTML, same for CSS.

    P.S. Sorry for double posting..

  15. @Roger - I’m glad you like my library btw. :-)

  16. April 4, 2007 by Roger Johansson (Author comment)

    About some jQuery users not being very likable, I can definitely see what Dean is getting at. It seems like every time someone posts a helpful article explaining how to do something with JavaScript, they get comments like “This is pointless. Your script is 37 lines and I could have done it on a single line with jQuery.”

    Well, duh. That’s completely missing the point.

    Anyway, nice to see some well-mannered jQuery folks here ;-). Karl, thanks for reading despite not agreeing with everything!

    And Dean - great work, once again.

  17. Too bad it doesn’t contain any visual effects ;)

  18. Yes! This is just what the doctor ordered! I’d almost given up on JavaScript and started letting ‘others’ deal with it. And now this little beauty, I’m sucked right back in.

Comments are disabled for this post (read why), but if you have spotted an error or have additional info that you think should be in this post, feel free to contact me.