Archive for February, 2007

AFLAX: The AJAX Library for the Adobe Flash Platform

Thursday, February 1st, 2007

The version 1.0 of AFLAX has been released :

“Developed by Paul Colton, the AFLAX technology is available as a library that enables developers to use JavaScript to fully utilize all of the features of Adobe’s Flash runtime — including graphics, networking, video and camera support.”

The demos are quite impressive : http://www.aflax.org/demos.htm

Javascript Coding rules

Thursday, February 1st, 2007

Here are some rules I constrain myself to, and that can be useful for others :

  1. Use good code conventions
  2. Check your code: JSLint (javascript tools bundle for textmate make it automatic)
  3. Minification of your code: JSMin
  4. GZIP the code, don’t obfuscate: Minification v. Obfuscation

You will effectively reduce errors and debugging time by following those advices.

Essential things to know about Javascript

Thursday, February 1st, 2007

Douglas Crockford has written some essential articles about javascript:

Here is a few of them:

There are others on his javascript homepage and I strongly recommend all of them !

Reusable code

Thursday, February 1st, 2007

Javascript prototype inheritance allows a lot of code re-use.

RE-USE I said !

So, why are you still coding ?!?

Go to http://www.brainjacked.com/, and find the piece of code you’re missing !

They use Yahoo! Tech groups to publish news, so you can get their rss feed to keep up-to-date !

Unit tests in Javascript

Thursday, February 1st, 2007

If you’re used to unit testing ( using JUnit in java, Test::Unit in Rails, etc… ), you might like to have a look at http://www.jsunit.net/

“It is essentially a port of JUnit to JavaScript. Also included is a platform for automating the execution of tests on multiple browsers and mutiple machines running different OSs.”

Debugging Javascript with Firebug 1.0

Thursday, February 1st, 2007

The new version of Firebug is finally released !!!

This is an awesome tool to debug and profile javascript. It has a lot of new features

compare to the previous releases.
Here is a great video of Joe Hewitt (Firebug’s author) about those new features :
http://yuiblog.com/blog/2007/01/26/video-hewitt-firebug/

I also recommend Firebug Lite that provides the console logger for other Browsers

Advanced Javascript Video

Thursday, February 1st, 2007

Douglas Crockford from Yahoo! made a few presentations about the Javascript Language.

They are just awesome and I don’t know how I was coding in Javascript before viewing them.

You can see them thanks to Yahoo! Videos, here are the links to the YUI-blog introducing them:

The slides from the presentations are available on the same page to keep

important things in mind…

Singleton pattern in Javascript

Thursday, February 1st, 2007

If you’d like to create just one instance of a Class, you’d better use this singleton pattern:


var singleton = function() {

  /* Private variables */

  var privateVariable;

  /* Private methods */

  function privateFunction(x) {
    // do something here...
  }

  return {

    /* Public variables */

    publicVariable = 15,

    /* Public methods */

    getVariable: function() {
      return privateVariable;
    },

    setVariable: function() {
      privateVariable = 18;
      privateFunction();
    }
  };

}();

The magic of this pattern lies in the instanciation of the singleton:

the main function is called directly due to the ‘()’ at the end.

How to set a timer within an object in Javascript

Thursday, February 1st, 2007

UPDATE: I don’t recommend this method anymore: it’s not a good idea to add functions to Object.prototype. Prefer adding this function to your object prototypes.

Here’s a useful method given by Douglas Crockford that can be added to Object.prototype :

Object.prototype.later = function( msec, method) {
  var that = this;
  var args = Array.prototype.slice.apply( arguments, [2] );

  if( typeof method === ’string’ ) {
    method = that[method];
 }
  setTimeout(function() {
    method.apply(that, args);
  }, msec);

  return that;
};

Then, you can call it on any object, the function will be called with the object scope:

myObject.later(1000, "methodName", arg1, arg2, .... ); // call myObject.methodName(arg1, arg2) in 1 second