* On 20 Apr 2009, Isaac Z. Schlueter wrote: 
> 
> I'm working on something similar to the namespace-esque thing you're
> talking about here.  However, rather than have the file create an
> object based on the filename (which is blackbox and magic and spooky),
> I plan to have it let you pass in an object that will be used as the
> global scope for that code.

FWIW I like this approach too.  Some years ago I wrote an interpreter
for SpiderMonkey (I didn't like jssh at the time) that had a Loader
class for executing JS script or loading native extensions.  Loader
had a method "export" that would add Loader methods to any object.
Its "load" method executed in "this".  Thus:

var o = new Object();
Loader.export(o);       // adds loader methods to o
o.load("file.js");      // executes file.js in o's "namespace"

Loader.export(this);    // add load() to global object

Loader.export(Object);  // extend Object with load capability
var p = new Object();
p.load("file.js");

Obviously you can extend this to extend class templates, even to the
extent of making load() available to any object instance.  It's very
flexible.  I recommend it if you're doing similar work in v8.

Loader.export() was actually implemented in JavaScript -- it didn't need
to be native because Loader.load() would always operate in "this"'s
scope.  (I think there may have been an exception where this == Loader.)

-- 
 -D.    [email protected]    NSIT    University of Chicago

--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to