Subj : Re: Creating classes/namespaces on the fly from existing functions? To : netscape.public.mozilla.jseng From : Shanti Rao Date : Mon Jan 10 2005 09:43 am > Now I do it like this: > var x=getLibrary("foo.js"); > > and getLibrary returns an (module) object. (the newly created (module) > object is passed as this to the foo.js to allow the script to decide if > it still wants to pollute the global namespace or not) > > This gets quite close to real namespaces. > > Jens > I like the idea of encapsulating library variables in thir own namespace. An interpreter would have to have two functions, since some code is intended to run inline: f = getLibrary("foo.js") includeLibrary("bar.js") With the former, there are a few minor glitches. Consider js>f = {Foo: function() {this.message = 'Foo'}}; js>a = new f.Foo() [object Object] js>a.constructor.name The last statement returns an empty string. Compare with js>function Bar() {this.message='Bar'}; js>b = new Bar [object Object] js>b.constructor.name Bar Shanti .