Activate your free membership today | Log-in

Monday, February 5th, 2007

DJAX: Language on top of JavaScript

Category: JavaScript, Library

<>p>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:
  1.  
  2. test = function() {
  3.     var primes1 = new Thread( 20, target=calcPrimes ) ;
  4.     primes1.elid = "res1" ;
  5.     primes1.start() ;   
  6.  
  7.     var primes2 = new Thread( 10, target=calcPrimes ) ;
  8.     primes2.elid = "res2" ;
  9.     primes2.start() ;
  10.  
  11.     var anim1 = new Thread( 20, realtime=true, target=animateBox ) ;
  12.     anim1.elid = "anim1" ; anim1.delay = 10 ;
  13.     anim1.start() ;
  14.         
  15.     var anim2 = new Thread( 20, realtime=true, target=animateBox ) ;
  16.     anim2.elid = "anim2" ; anim2.delay = 20 ;
  17.     anim2.start() ;
  18. }
  19.  

Related Content:

  • Chapter 22: JavaScript security
    JavaScript continues to find adherents. But this scripting language can be used by malicious hacks to eat up memory .. and worse. Learn about Java...
  • JavaScript Learning Guide
    This SearchDomino.com guide introduces you to JavaScript in a Notes/Domino environment, explains best practices and pitfalls to avoid and provides...
  • JavaScript
    JavaScript is an interpreted programming or script language from...
  • Java Script
    JavaScript is an interpreted programming or script language from...
  • Use JavaScript with the iPhone to create smart phone apps
    Objective-C remains the most prevalent iPhone development language, but JavaScript has been gaining traction as a viable alternative. You can use...

Posted by Dion Almaer at 7:13 am
10 Comments

++---
2.5 rating from 17 votes

10 Comments »

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
http://code.google.com/p/djax/

Somebody should’ve googled before choosing a name.

Comment by Brian — February 5, 2007

This reminds me of haxe: http://haxe.org

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.