Another Ajaxian post today, this one on DJAX, a language that sits on top of javascript. This reminds me of haxe and to a lesser extent of things like the Google Toolkit. Still, I think this is a good idea, but it definitely represents that "next level" of javascript that may actually make it harder for people to adopt. Another programming language? A lot of javascripters barely can handle javascript.

That said, on a personal level, I find it interesting and I want to dig into these kinds of solutions because they are so promising. Anyone have an opinion here?

Hamish Friedlander has created djax, a language translator that takes code written in a javascript superset, and turns it into regular-ol' javascript.

What does the language try to give you?

  • Continuations (ish). Suspend a javascript function anywhere, and start it again later easily. Code synchronous ajax without locking the browser. sleep().
  • Threads. Execute long-running jobs in the background, while animations run smoothly in the foreground. No browser-lockups.
  • Generators. Iterate over anything. Easily.
  • ExtendedArguments. Variable-length arguments, keyword arguments, default values. Without the pain of the arguments property
  • Compatibility. Any javascript function should still work fine called from or translated through djax. Mochikit's self test passes all tests after translation.

You can see a threading example in action.

JavaScript:
test = function() {
    var primes1 = new Thread( 20, target=calcPrimes ) ;
    primes1.elid = "res1" ;
    primes1.start() ;

    var primes2 = new Thread( 10, target=calcPrimes ) ;
    primes2.elid = "res2" ;
    primes2.start() ;

    var anim1 = new Thread( 20, realtime=true, target=animateBox ) ;
    anim1.elid = "anim1" ; anim1.delay = 10 ;
    anim1.start() ;

    var anim2 = new Thread( 20, realtime=true, target=animateBox ) ;
    anim2.elid = "anim2" ; anim2.delay = 20 ;
    anim2.start() ;
}

drag to resize