Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

CoffeeScript and Titanium

Recently a nice blog was written about using CoffeeScript to build Titanium apps: http://rigelgroupllc.com/wp/blog/building-iphone-apps-with-titanium-and-coffeescript

It would be interesting if there are a lot of people using it this way… Anybody built anything more than a toy app with CoffeeScript? Does anybody think it should be a built-in option in Titanium?

At the moment there are two problems with CoffeeScript:

  1. It's mostly for non-Windows use (it requires node.js, which is not windows friendly).
  2. It unfortunately forces developers to use the python style code blocks.

To quickly compile CoffeeScript files to JavaScript on Windows you can use XCoffeeScript ( http://bit.ly/9wplmE ). At some point it will actually support extended CoffeeScript syntax to allow developers to use braces for function blocks if they want it :-)

— asked September 3rd 2010 by Kyle Quest
  • coffeescript

3 Answers

  • The biggest advantage to using CoffeeScript is it lets you write better Javascript. Especially in Titanium, the global namespace can be a problem, so CoffeeScript helps manage that by automatically putting everything inside anonymous functions. Sure, you can do that yourself, but CoffeeScript just makes it more pleasant to write.

    And remember, the CoffeeScript gets translated into straight, readable Javascript, so you can mix and match or just stop using CoffeeScript at any time, you still have all the Javascript code at your disposal.

    We have also found that using CoffeeScript to write reusable widgets works great, for example we have an HTTPClient wrapper that is backed by a local database cache, which is easily packaged and used in many different projects of ours. We plan on putting up another blog post about that soon, with the code.

    — answered September 3rd 2010 by John Lynch
  • This is great! I am greatly interested in the 'HTTPClient wrapper that is backed by a local database cache' blog, if it is published.


    — answered September 4th 2010 by Peter Lum
  • John's post about using Coffeescript with Titanium was extremely timely for me. I had just begun to look at Titanium, and I've liked the syntax of Coffeescript more than JavaScript. The combo looked like a winner. And, as it turns out, it has been a winner for us. I'm building an iPhone app right now using essentially 100% Coffeescript (aside from app.js). This is a real app, which will have location services use, talk to a web service, do monetary transactions, etc.

    The combination of Coffeescript and Titanium has allowed me to build this app quickly. Titanium is helping me build the app much faster than I believe I'd have been able to do with regular native/Objective-C tools, and Coffeescript is making the JavaScript aspect go even faster (and simply more pleasantly for me).

    Also, I believe John's post about the caching HTTPClient wrapper is now up here.

    — answered September 28th 2010 by Christopher Bailey
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.