Wednesday, April 16th, 2008

Three Helpful JavaScript Libraries

Category: JavaScript, Library

Oliver Steele has posted on three small JavaScript libraries that he carries around in his toolbox as he goes from project to project.

Fluently — Construction Kit for Chainable Methods

Fluently lets you build chainable methods, which Oliver used to build a mock test framework.

javascript

  1. var o = Fluently.make(function(define) {
  2.     define(‘fn1’, function() {console.info(‘called fn1’)});
  3.     define(‘fn2’, function() {console.info(‘called fn2’)});
  4.     define.empty(‘and’);
  5.     define.alias(‘fn3’, ‘fn1’);
  6.     define.modifier(‘not’);
  7. });
  8.  
  9. o.fn3(); // same as o.fn1()
  10. o.fn1().and.fn2() // same as o.fn1().fn2()
  11. o.fn1().and.not.fn2() // options.not is set when fn2 is called

MOP JS

MOP JS defines utilities for JavaScript metaprogramming. You don’t think you need it until you try asynchronous programming, where some methods don’t have enough information to operate until the response to another method’s asynchronous request have returned.

javascript

  1. new MOP.MethodReplacer(object, methods)
  2. MOP.withMethodOverridesCallback(object, methods, fn)
  3. MOP.withDeferredMethods(object, methodNames, fn)

Collections JS

Collections JS defines framework-independent JavaScript collection methods, for use in browser JavaScript and in ActionScript / OpenLaszlo.

The Array and String methods extend the class prototype; the Hash methods use a proxying wrapper to avoid prototype pollution. The methods with the same names as the ECMAScript 1.6+ extensions have the same spec as those; the ones with the same name as prototype extensions have the same spec as those in the Prototype library; and there’s a few odds and ends such as String#capitalize.

I use this when I don’t want the overhead of Prototype, or want to use these functions in an environment that Prototype doesn’t run on, such as OpenLaszlo. It has some overlap with Functional, but isn’t nearly so radical — this can be an advantage.

Thanks for sharing Oliver!

Posted by Dion Almaer at 12:06 pm
3 Comments

+++--
3 rating from 24 votes

3 Comments »

Comments feed TrackBack URI

That collection.js looks pretty interesting for quick, lightweight projects that don’t need a full JS library behind them.

Comment by tj111 — April 16, 2008

test

Comment by frolic — April 16, 2008

I love Oliver’s stuff. It always makes me think.

Comment by Nosredna — April 16, 2008

Leave a comment

You must be logged in to post a comment.