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:

Inconsistent enumeration across platforms

instanceof doesn’t always work

doesn’t always work typeof is inconsistent (RegExps identify as type “function” in Mozilla browsers)

is inconsistent (RegExps identify as type “function” in Mozilla browsers) Consistent object/platform detection

Other various bugs

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.

Classes/Modules/Packages

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

Functions

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

Summary

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:

http://base2.googlecode.com/svn/version/1.0(beta2)/base2-p.js (minified)

http://base2.googlecode.com/svn/version/1.0(beta2)/src/base2.js (source code)

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