login/register

Snip!t from collection of Alan Dix

see all channels for Alan Dix

Snip
summary

One thing that I absolutely adore is the sheer embeddabi...
Since JavaScript, alone, is so dumb (we've become spoile ...
We can start by taking a look at some of the most popula ...
One thing is the same in all the interpreter implementat ...
... it gen

John Resig - Spicing Up Embedded JavaScript
http://ejohn.org/blog/spicing-up-embedded-javascript/

Categories

/Channels/techie/JavaScript

[ go to category ]

For Snip

loading snip actions ...

For Page

loading url actions ...

One thing that I absolutely adore is the sheer embeddability of JavaScript. It's a (comparatively) simple language that is fiercely flexible. I tend to liken JavaScript to water - alone it's painfully simple but it can take the form of its container - and mixing it with anything enhances its flavor.

Since JavaScript, alone, is so dumb (we've become spoiled by browsers which provide DOM, setTimeout/setInterval, and even a global object reference - none of which are necessarily required my an ECMAScript implementation) we must rely upon the spice of 'larger' languages to help it gain some taste.

We can start by taking a look at some of the most popular languages that are available today: Python, Perl, PHP, Ruby, and Java -- all of which have, at least, one embeddable JavaScript interpreter.

One thing is the same in all the interpreter implementations, as well, they all have the ability to introduce (at least) simple objects into interpreter (from the parent language) and extract values again. Sometimes this may be as simple as executing a JavaScript function and getting its return value (which is often translated from its internal JavaScript form back into the native language).

There's a couple points upon which I like to evaluate the embeddability of a JavaScript interpreter, specifically:

  1. Object Translation: If objects/values are passed to/from the interpreter to/from the native language - is that translation handled automatically?
  2. Simplicity: How hard is it to get up-and-running? (Is extra compilation required or is it written using native language code?)
  3. Bleed-through: Can JavaScript communicate to the base language or is it a one-way-street?

The first point is the easiest one to find compatibility with - virtually all embeddable JavaScript interpreters do some form of object translation. Some do it better (like JE and Rhino) but it generally shouldn't be a problem for simple scripts.

HTML

<p>One thing that I absolutely adore is the sheer embeddability of JavaScript. It's a (comparatively) simple language that is fiercely flexible. I tend to liken JavaScript to water - alone it's painfully simple but it can take the form of its container - and mixing it with anything enhances its flavor.</p> <p>Since JavaScript, alone, is so dumb (we've become spoiled by browsers which provide DOM, setTimeout/setInterval, and even a global object reference - none of which are necessarily required my an ECMAScript implementation) we must rely upon the spice of 'larger' languages to help it gain some taste.</p> <p>We can start by taking a look at some of the most popular languages that are available today: Python, Perl, PHP, Ruby, and Java -- all of which have, at least, one embeddable JavaScript interpreter.</p> <p>One thing is the same in all the interpreter implementations, as well, they all have the ability to introduce (at least) simple objects into interpreter (from the parent language) and extract values again. Sometimes this may be as simple as executing a JavaScript function and getting its return value (which is often translated from its internal JavaScript form back into the native language).</p> <p>There's a couple points upon which I like to evaluate the embeddability of a JavaScript interpreter, specifically:</p> <ol> <li><b>Object Translation:</b> If objects/values are passed to/from the interpreter to/from the native language - is that translation handled automatically?</li> <li><b>Simplicity:</b> How hard is it to get up-and-running? (Is extra compilation required or is it written using native language code?)</li> <li><b>Bleed-through:</b> Can JavaScript communicate to the base language or is it a one-way-street?</li> </ol> <p>The first point is the easiest one to find compatibility with - virtually all embeddable JavaScript interpreters do some form of object translation. Some do it better (like JE and Rhino) but it generally shouldn't be a problem for simple scripts.</p>