File Under: JavaScript

Zaphod Gives JavaScript Developers Two-Headed Power

What’s become so complicated you need two heads to figure it out? JavaScript of course.

Mozilla Labs recently launched a new project dubbed Zaphod, named for the two-headed President of the Galaxy in The Hitchhiker’s Guide to the Galaxy. Zaphod is a Firefox add-on that has two “heads” of its own.

Zaphod’s primary head, in this case, makes it simple to switch JavaScript rendering engines. Zaphod’s other “head” is the Narcissus JavaScript engine, which is a JavaScript engine written in JavaScript. Narcissus is great for experimenting with JavaScript, but it lacked an easy way to run your code within the browser, which is where Zaphod comes in.

The add-on lets you run the Narcissus engine instead of SpiderMonkey, Firefox’s default JavaScript engine. Just install Zaphod and put some “application/narcissus” script tags in your page, and Firefox will render your scripts using Narcissus.

You may be wondering why in the world anyone would want to run JavaScript code through a JavaScript Engine written in JavaScript (you may also be thinking that “the Escher” would have been an equally compelling name for the project). The answer is because you can change how the actual interpreter and compiler work. Sure you could re-write SpiderMonkey in your spare time, but that’s quite a task compared to modifying a few lines of JavaScript in Narcissus.

So, why modify the actual rendering engine? It could help the community reach decisions about what new features should be added JavaScript, what those features should look like and how they should behave. Or perhaps you’d just like to experiment with the JavaScript language itself, rather than what you can do with the language.

If you’d like to experiment with Narcissus, just add this meta tag to your HTML page:

<meta http-equiv="Content-Script-Type" content="application/narcissus" />

Then install the Zaphod add-on and reload your page. From there you’re just a few experiments away from revolutionizing the web. If you’d like to see a few of Mozilla’s experiments to get some idea of what you can do, head over the Narcissus page and take a look.

Don’t Panic photo by Jim Linwood/Flickr/CC

See Also: