base2: An Introduction

I’ve been working on base2 for a couple of years now and it is finally ready for a beta release. With base2 I aim to solve various problems with inconsistent JavaScript implementations and add a little sugar to the language at the same time.

These are the problems that I’ve tried to solve:

And the sugar:

And I’ve tried to adhere to my own rules for JavaScript library development as much as possible.:-)

Here is a brief outline of the base2 API. In subsequent blog posts I’ll drill into specific classes and functions in more detail.


The base class for inheritance. Based on my old Base class.
A hash class. Based on ES4’s Map.
A Map that is more array-like. Items may be referenced by index as well by key.
A Collection of regular expressions and their associated replacement values. For building powerful parsers.
A mechanism for grouping functions that operate on particular types of object. I will explain this in more detail in a later blog post.
A mechanism for grouping functions and classes. base2.DOM is an example of a Package. I will provide an overview of this class in a later blog post.
A Module that defines useful methods for enumeration (map, filter, etc).
A Package that defines optional extensions to JavaScript’s built-in objects (Array2, Date2 and String2).


I won’t bother to describe the functions here you can read the online documentation for more information. Hopefully, you can guess what most of the functions do. I will explain some of them in more detail in a later blog post.

assignID, detect, Undefined, Null, True, False


base2 is a lightweight library that irons out all the annoying differences in JavaScript implementations. It provides the additional functionality from JavaScript 1.6+ that only Mozilla browsers implement. It also adds some features from ES4. The library is only 6KB (gzipped). You can download it from googlecode or link to it directly from your web page: (minified) (source code)

As previously mentioned, I intend to showcase some of the features of base2 in individual blog posts. Stay tuned.

Comments (13)

Leave a comment

Congrats on the (beta) release, Dean! Do you know of any sites that are already using your code? (previous versions included)

Hi Dean, It seems a great piece of work. My compliments! I’m thinking of using base2 in the future releases of PassPack.

Wow the potential for RegGrp is awesome. Regular Expressions is probably my least favorite (probably because I would consider it my weakest link) task to do but I find myself needing them all the time. Awesome stuff!

  • Comment by: Justin
  • Posted:

I forgot to mention this in my introduction. base2 is not dependent on the browser. I’ve successfully used it in Rhino and WSH environments as well.

  • Comment by: -dean
  • Posted:

@Ermanno: By default regular expressions are case-sensitive.

  • Comment by: -dean
  • Posted:

@Ermanno: Yes that’s right.

I intend to write a blog post to describe the RegGrp object in more detail. It powers packer and the syntax-highlighter that I use on this site. It is also the engine of the base2 implementation of the Selectors API.

  • Comment by: -dean
  • Posted:

[…] Dean wrote up an introduction to base2 where he covers the problems that he is trying to solve: […]

[…] Dean Edwards: base2: An Introduction – […]

[…] base2 ist eine Library die Javascript um einige Funktionen erweitert und versucht die Konsistenz zwischen den einzelnen Browser Implementierungen zu verbessern. In der base2 Einführung wird alles genau erklärt. […]

[…] I am obviously a fan of JavaScript.  Continuations and closures are so money you don’t even know it.  Yet, JavaScript is often criticized for not being an Object Oriented Language (it can be though). […]

[…] mimic class-based inheritance, without creating classes, in more than one way. See Dean Edwards’ base2, qooxdoo, Prototype for a few implementations. Most of the changes in the new specification have […]

[…] mimic class-based inheritance, without creating classes, in more than one way. See Dean Edwards’ base2, qooxdoo, Prototype for a few […]


We use base2 in KSS (Kinetic Style Sheets, for css querying. Recently we are aware of an issue that happens identically on Safari 3.1 and Mozilla Chrome (that is based on Safari 3.1). We use base2-dom-fp.js version 1.0 (beta 2), with a size of 39260.

What happens, it seems, that selections that contain uppercase characters in the id or class, fails. With all lowercase characters the problem does not occur.

Are you aware of this issue? (Please let me know if I should report somewhere else, or if you require more information.)

Thanks in advance!

Best wishes,

Balazs Ree

  • Comment by: Balazs Ree
  • Posted:

Comments are closed.