Hi Tobias,

By namespaced classes do you mean support for classes named like:

com.google.MyTestClass
com.yahoo.MyTestClass

?

If thats the case then I did add some more fuctionality to support
this together with a Prototype.Namespace variable that allows you to
set the current namespace so you don't have to refer to classes by
their full name. The code is probably nowhere near suitable for
addition to Prototype as-is but I'll post it up when I get home for
you to look at anyway.

Regards
Gareth

On Feb 21, 11:44 am, Tobie Langel <[EMAIL PROTECTED]> wrote:
> Hi,
>
> That unfortunately doesn't solve the problem for namespaced classes:
>
> var Vehicles = {};
>
> Class.create('Vehicle.Cars', {});
>
> Best,
>
> Tobie
>
> On Feb 21, 12:10 pm, GarethAtFlignet <[EMAIL PROTECTED]>
> wrote:
>
>
>
>
>
> > As prototype provides a convenient OO approach to javascript coding
> > through its object inheritance model it would be 'really' useful if
> > you could query the name of the current class through a getClassName()
> > method or similar like you can in many other languages.
>
> > There is a post at:
>
> >http://groups.google.com/group/rubyonrails-spinoffs/browse_thread/thr...
>
> > which discusses an approach to achieve this and seems backward
> > compatible.
>
> > Code and usage below. Any chance of including 'something' like this in
> > a future release?
>
> > ---
>
> > Usage:
>
> > <script>
> > Class.create("Vehicle", { });
> > Class.create("Car", Vehicle, { });    // Car extends Vehicle
> > Class.create("Passat", Car, { });     // Passat extends Car
>
> > // create one of each
> > var v = new Vehicle();
> > var c = new Car();
> > var p = new Passat();
>
> > alert(v.getClassName());
> > alert(c.getClassName());
> > alert(p.getClassName());
> > </script>
>
> > ---
>
> > Class rewrite:
>
> > var Class = {
> >   create: function() {
>
> >     var parent = null, properties = $A(arguments);
>
> >     // retrieve the class name
> >     var className = "";
> >     if(Object.isString(properties[0])) {
> >                 className = properties.shift();
> >     }
>
> >         // get the parent
> >     if (Object.isFunction(properties[0]))
> >       parent = properties.shift();
>
> >     function klass() {
> >                 this.initialize.apply(this, arguments);
> >     }
>
> >     Object.extend(klass, Class.Methods);
> >     klass.superclass = parent;
> >     klass.subclasses = [];
>
> >     // reference the class by name
> >         if(className!="") {
> >                 window[className] = klass;
> >     }
>
> >     // store the classname as klass.constructor.className
> >     // and add a method getClassName() to all classes
> >     klass.className = className;
> >         klass.prototype.constructor.addMethods({
> >                 getClassName: function() {
> >                         return this.constructor.className;
> >                 }
> >         });
>
> >     if (parent) {
> >       var subclass = function() { };
> >       subclass.prototype = parent.prototype;
> >       klass.prototype = new subclass;
> >       parent.subclasses.push(klass);
> >     }
>
> >     for (var i = 0; i < properties.length; i++)
> >       klass.addMethods(properties[i]);
>
> >     if (!klass.prototype.initialize)
> >       klass.prototype.initialize = Prototype.emptyFunction;
>
> >     klass.prototype.constructor = klass;
>
> >     return klass;
> >   }
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to