Mascara: ECMAScript 4 → Classic JavaScript translator

Try it Download About Documentation Weblog Contact
Mascara described by others:

John Resig: Writing ECMAScript 4, Today

A very cool new utility has just been released...
by John Resig, creator of JQuery.

Ajaxian: Mascara: Putting lipstick on JavaScript?

InfoWorld: JavaScript creator ponders past, future

An interview with Brendan Eich, the creator of JavaScript. Mascara is mentioned on the last page of the interview.

About Mascara

Mascara is a tool that translates ECMAScript 4 to classic JavaScript, thereby enabling features like type-checking, classes and namespaces in JavaScript today.

ECMAScript 4 is the next generation of JavaScript, which is beeing developed by ECMA International with participation by Mozilla, Apple, Adobe, Microsoft and others.

Mascara is written in Python. It should run on any platform that Python runs on, which is practically everywhere.

Mascara is still under development, but a preview version can be downloaded now.

Why write ECMAScript 4 and translate to JavaScript?

As the web evolves, Javascript applications grow increasingly complex. Classic JavaScript is flexible, but also minimalistic, and was not intended for large applications. It lacks features like a namespace system, classes, type verification and so on, which makes developing complex applications manageable. Complex JavaScript application can easily turn into buggy maintenance nightmares.

ECMAScript 4 is the upcoming upgrade to JavaScript, and extends the language with improved facilities for encapsulation, consistency, error checking, and library building - features which makes it more suited for developing larger applications.

This tool allows developers to write ECMAScript 4 code and take advantage of its features, while generating "object code" that will run in any browser today. In the future ECMAScript will (hopefully!) by supported natively by mainstream browsers, but as long as a significant share of browsers only support classic javascript, this tool will be useful.

ECMAScript 4 is backwards compatible with JavaScript, and works seamless together with classic javascript. You can upgrade code to ECMAScript one piece at a time, and integrate with libraries written in classic JavaScript. The type-inference system gives you additional compile-time verification even on code written in purely classic JavaScript.

Limitations: Some features of ECMAScript 4 is not possible to support by this tool. For example runtime introspective access to type or namespace values are not possible since these are erased after the compile-time verification. Some features like catch-all metods requires support in the target runtime, and is therefore not possible to support fully cross-browser. Generators/yield will probably not be supported, but the jury is still out on that issue.