Zaphod — Mozilla’s new experiment, a JavaScript engine written in JavaScript!

Zaphod — Mozilla’s new experiment, a JavaScript engine written in JavaScript!

One might imagine, what is the point of having a JavaScript engine written in a traditionally slow language such as JavaScript itself? We don’t want to delude you into thinking that everything done by the open source community has to have a reason, but this one does, and a good one at that.

While developing applications in any language of any kind, there is one thing which remains the same, the language syntax whether you like it or not. You cannot change how the interpreter / compiler itself works. What if you could?

Zaphod is just such an experiment. It is an add-on which bundles the Narcissus JavaScript engine with your browser, and lets you use it to run your JavaScript code instead of on the Firefox JaegerMonkey / TraceMonkey / SpiderMonkey engine directly.

While Narcissus is the JavaScript engine itself, it is not well integrated into the browser, and that is where Zaphod comes in. Zaphod integrates Narcissus into Firefox making it easier to use the alternative engine to run your code.

However, since your code will be running on a engine which itself is being interpreted as it runs, don’t expect it to be blazing fast! Were you sacrifice on speed, you will gain in customizability. Narcissus allows you to develop modifications to the engine itself, and to test new features without needing to work with complicated low-level C / C code of Spidermonkey or some other JavaScript engine. You can in a sense “hack the language itself.”

Another benefit Mozilla enlists is the ease with which you can share your ideas with others. Since the engine is now separate from the browser itself, you can modify it separately and share it separately.
Narcissus is simpler to down with that other JavaScript engine due to the fact that it is written in JavaScript itself, a language already familiar to any JavaScript programmers.

Since Narcissus isn’t suitable for the JavaScript applications which a browser is likely to encounter on the web —such as GMail— it requires that developers make use of a special script tag for code which they want executed in the new engine. There is an option for having all the code run in the engine with a simple switch.

So if you’re a JavaScript developer, who’d like to start playing with the language itself, Zaphod is the tool for you. To find out more about Zaphod head over to its page on Mozilla labs, and keep a towel handy.

Kshitij Sobti
Digit.in
Logo
Digit.in
Logo