Currently Prototype lacks a namespace creation function. I know, the function is quite simple, and I can write it my self (which I have done), but do you think it will be nice to have one built in Prototype?
The basics of the function is quite easy function Namespace(identifier) { var cursor = window; if (identifier) { var spaces = identifier.split("."); for (var i = 0; i < spaces.length; i++) { if (!cursor[spaces[i]]) cursor[spaces[i]] = {}; cursor = cursor[spaces[i]]; } } } Or if there is need to extend the namespace with classes function Namespace(identifier) { var cursor = window, klasses = arguments[1] || false; if (identifier) { var spaces = identifier.split("."); for (var i = 0; i < spaces.length; i++) { if (!cursor[spaces[i]]) cursor[spaces[i]] = {}; cursor = cursor[spaces[i]]; } } if (klasses) { for (var klass in klasses) { cursor[klass] = klasses[klass]; } } } Noting fancy. I've seen far more complicated examples, which can do tons more stuff. Sample usage would be: Namespace("My.Name.Space"); My.Name.Space.MyClass = Class.create ... In addition, I also set two additional fields to indicate that My.Name.Space spaces are indeed namespaces (and not classes or fields) as well as setting the name of each space. But this might be over- doing for some, so it's not in the snippet. Any thought on that one? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to prototype-core-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~----------~----~----~----~------~----~------~--~---