Monday, February 5th, 2007

DJAX: Language on top of JavaScript

Category: JavaScript, Library

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.


  1. test = function() {
  2.     var primes1 = new Thread( 20, target=calcPrimes ) ;
  3.     primes1.elid = "res1" ;
  4.     primes1.start() ;  
  6.     var primes2 = new Thread( 10, target=calcPrimes ) ;
  7.     primes2.elid = "res2" ;
  8.     primes2.start() ;
  10.     var anim1 = new Thread( 20, realtime=true, target=animateBox ) ;
  11.     anim1.elid = "anim1" ; anim1.delay = 10 ;
  12.     anim1.start() ;
  14.     var anim2 = new Thread( 20, realtime=true, target=animateBox ) ;
  15.     anim2.elid = "anim2" ; anim2.delay = 20 ;
  16.     anim2.start() ;
  17. }

Posted by Dion Almaer at 7:13 am

2.6 rating from 22 votes


Comments feed TrackBack URI

Nice concept .. but I remember that I’ve already another framework trying to introduce Thread already ?

Anyway, specifications seem to be amazing but I’m sceptic with the Thread demo as It freeze time by time on my machine. And the animation demo was quite simple… compare to mootools physic demo I’ve saw…

But best luck anyway ! It nice to see many growing idea outhere !

Comment by Nicolas — February 5, 2007

Hurrah, I’m on ajaxian :). Let’s see if my server survives.
Nicolas: Firefox seems to have a duty cycle limit on javascript I haven’t gotten around yet – it’s much smoother on IE or Opera. The animation is simple so that the code is clear – if people _really_ want a flashy demo I’ll knock up a nicer animation.

Comment by Hamish Friedlander — February 5, 2007

I downloaded it, but what I am supposed to do with it, to get going? I assume there is something that does the JS-compilation right (djx -> js)? I am supposed to run djax.exe?

Comment by Ajax 2.0 Developer — February 5, 2007

This isn’t really the place to discuss it, but yes. djax –help should give you a list of options. “djax *.djx” will convert all .djx files into .js. “djax -x .out.js *.js” will convert all .js files into .out.js files (for converting libraries like Mochikit). “djax -o out.js out.djx” will convert just one file.
The site is a trac for a reason. Please edit it. That way other people get to see the answers too.

Comment by Hamish Friedlander — February 5, 2007

Sorry, maybe I misread your question. Currently the translator is command line only. There isn’t a GUI you can use just by double-clicking on the file.

Comment by Hamish Friedlander — February 5, 2007

I like flashing demos :P hehe.

it looks cool, but i found it a little jumpy in firefox too… trying IE now.

Comment by Dougal Matthews — February 5, 2007

This is a little confusing…

djax : Django Ajax library

Somebody should’ve googled before choosing a name.

Comment by Brian — February 5, 2007

This reminds me of haxe:

Comment by Aaron N. — February 5, 2007

Nice demo, a little lag time every so often in Firefox but it seems you’re aware of that. Good luck.

Comment by Andy Kant — February 5, 2007

Hi Hamish :)
Well I like flashy animation showing how concept can be use in real life :)
It surely not easy to emulate Thread so I’ll surely take a look at your work :D

Best luck !

Comment by Nicolas — February 6, 2007

Leave a comment

You must be logged in to post a comment.