Subj : Re: Creating classes/namespaces on the fly from existing functions? To : netscape.public.mozilla.jseng From : Shanti Rao Date : Tue Jan 11 2005 02:46 pm >> f = getLibrary("foo.js") >> includeLibrary("bar.js") >> >> With the former, there are a few minor glitches. Consider >> >> js>f = {Foo: function() {this.message = 'Foo'}}; > > > But why must getLibrary be implemented so as to use anonymous functions > if "foo.js" contains named function declarations? > > /be > That is exactly the problem with using an object when you really wanted a namespace. For the sake of argument, assume that "foo.js" contains a named function Foo(), and getLibrary() makes Foo() (formerly a global object in foo.js) into a property of an object when included in another script. Now that I think about it some more, it's sufficiently confusing to promote the minor glitch into a major irritation. It makes it very difficult to convert a stand-along script into a library. This conception of a getLibrary() function will probably be a failure. An include() function still works, so long as you don't unintentionally use the same global variable name in two different source files. This highlights the fact that creating a class is very different from creating a namespace. Shanti PS. Straw man: what about a 'library' as a separate thread with a COM-like messaging interface? A synchronous function call would send a message and wait for a reply. Or not wait. It invokes buzzwords like grid computing and transaction processing. .