Subj : Re: Creating classes/namespaces on the fly from existing functions? To : netscape.public.mozilla.jseng From : Jens Thiele Date : Fri Jan 07 2005 11:20 am bubbfree@gmail.com schrieb: > mainFile.js: > > useLibrary("externalFile1.js"); > useLibrary("externalFile2.js"); > externalFile1.a(); > externalFile1.b(5, 10); > externalFile2.a(); > > > (of course, the file name would have to conform with class/variable > naming syntax). > > The object or namespace 'externalFile1' would be dynamically created by > the useLibrary() implementation, and all functions found in that file > would be added as member functions of the newly created > object/namespace. I have done this () but added another IMHO better approach after looking at jsolait (). (the new version is in CVS only at the moment http://developer.berlios.de/cvs/?group_id=1662) 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 .