Friday, March 11, 2011

Kaffeine.js - A cleaned up JavaScript

Well, I found one language pretty close to what I was looking for in a better JavaScript:

http://weepy.github.com/kaffeine/

  • Backwards compatible with JavaScript
  • Uses @foo to to get the "real" this.foo
  • Uses CPS folding to flatten callbacks
  • Multiline strings, which come in handy
  • for(n of [1, 2, 3]) array iteration
  • String interpolation: "#{foo} was here"
  • Implicit functions: (foo) { alert(foo); }
  • Pipe operator for chaining the first arg
  • Default arguments, optional call parens
  • Implicit return (nice with implicit funcs)

Out of those, I think callback unfolding and the pipe operator are the most interesting beyond adding some niceties:
  ok = stomach.save!()
  meal.complete = ok
translates to:
  stomach.save(function(ok) {
    meal.complete = ok
  })
and...
  result = input | fn args
translates to:
  result = __.fn.call(this, input, args)