dean.edwards.name/weblog/2007/12/base2-intro/

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.

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.

Comments (19)

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 [...]

Hi!

We use base2 in KSS (Kinetic Style Sheets, http://kssproject.org) 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:

Vocation development, in contrast, is often viewed as more of any big snapshot view. While advice can be something people seek to meet up with an speedy need, career progress is an issue that unfolds after some time. The book definition connected with development, seeing that noted by means of Webster is usually, “the react, process, or reaction to developing. http://www.collegecreditcareersnetwork.net

Life-long employment opportunities and earning a living for one supervisor our overall working life is usually a thing connected with past. With the current fast-paced world wide economy, careers in addition to industries often change in addition to come in addition to go over night. http://www.careerfastrak.net

Prior to make almost any decision pertaining to your career you should assess by yourself first. Considering that the inherent power, skills in addition to values usually are most helpful what you should make vocation choices. You work with self lab tests tools to put it differently we can certainly say a career test for just a self analysis test. A vocation test means that you can making decisions on your career. Furthermore, it creates the ideal list connected with occupation in addition to gathers suitable information on your career. http://www.constructioncareeraustin.net

Both equally career tips and vocation development are necessary components a highly effective personal vocation exploration. Understanding most of these foundational words will ensure you get what you would like, and for the right time period. http://www.usa-technology.net

Vocation advice right now comes in all of the sizes and heights. It’s simple get “lost from the lingo” although understanding many basic definitions can assist ensure you get the suitable support for you. To said simply, whether you would like career tips or vocation development will depend on in which you are on your career journey. http://www.technews404.net

Doing the vital decision to search for a vocation change soon after 50 normally isn’t going to come collected from one of event or maybe one happening. Rather is it doesn’t slow trickle, drip connected with events of which trigger choosing one. http://www.inceptiontech.net

Leave A Comment

Line and paragraph breaks automatic, email address never displayed. Some HTML allowed.