New feature for spidermonkey: registerClass()


As I explained in my previous blogpost, you can export objects to spidermonkey by using the assign() function on this object. While it’s enough for basic cases, It’s not enough for complex situations where Javascript need to create itself objects instances.

Solution

Tonight I worked on the solution named “registerClass()“. As examples are better than words, here is how it works:

/* first create context */
$ctx = new JSContext();
/* register mysqli */
$ctx->registerClass('mysqli');

Then in your javascript source:

db = new mysqli('host', 'user', 'pass', 'db')
res = db.query('SELECT * FROM t1');
while (line = res.fetch_assoc())
{
    // do something with line
}

As you can see, this function allow you to instanciate objects yourself in Javascript, providing more power and flexibility. This function will be available tomorrow morning in the SVN.

, , , ,

  1. #1 by harald on February 24, 2009 - 4:14 pm

    finally … this seems to be exactly what i’ve been looking for, for a long time now. can’t wait to play around with it. many thanks!

(will not be published)