Hi,

Another option is to give the classes that you're using in this way a
unique ID:
* * * *
(function() {
    var uniqueClassIDAllocator = 0;

    Class.createSpecial = Class_createSpecial;
    function Class_createSpecial() {
        var clz = Class.create.apply(Class, arguments);
        clz.classID = ++uniqueClassIDAllocator;
        return clz;
    }
})();

var MyCoolClass = Class.createSpecial(...);
* * * *

If you don't want to have a `createSpecial` function, you could always
assign these IDs if/when a class is used to extend elements (e.g., in
a lazy way), but I prefer the explicit `createSpecial` because it
happens at the time the class is created, as an explicit action of the
author.

FWIW,

-- T.J. :-)

On Dec 17, 2:46 pm, Luke <kickingje...@gmail.com> wrote:
> Ok, thanks T.J.,
>
> I really wanted to get the name of the Class as a string. The reason
> is this:
>
> I'm working on a project that lets you create really simple webpages
> by adding, editing and removing objects (images, text, ..) to your
> page. To structure my code I do 2 things:
> 1.) I create classes for all objects on the page (for instance a
> general object-class, that holds general functions for editing,
> removing, etc and subclasses that inherit from the general class and
> implement their specific editing etc-functions (like for editing
> images, texts, etc)). Then I take the editable dom-elements of the
> page and extend them with the methods of the classes (I extend an
> editable image with the image-class etc) excluding methods like
> "initilize" or "constructor". That way I can make use of class-
> inheritance and still have that sweet syntactic sugar like $
> ('myImage').edit() (actually it's $('myImage').rbEdit() because of
> possible name-conflicts).
>
> Now what I want to prevent is that a DOM-Object get's extended by same
> class twice, because that would overwrite existing values, so I
> thought I might save what classes an object has already been extended
> with, and stop before it gets extended twice. But I'll think I'll
> define the classname as a property in the class itself then, and maybe
> throw an error if the classname has not been set.
>
> On Dec 17, 3:08 pm, "T.J. Crowder" <t...@crowdersoftware.com> wrote:
>
>
>
>
>
>
>
> > Bernard,
>
> > 1. No need to be offensive. If you think a question is beneath you, by
> > all means ignore it rather than moaning into everyone's mailbox.
>
> > 2. This question is almost certainly about Prototype's `Class`
> > feature, not JavaScript. Yes, if you know JavaScript well you
> > automatically know the answer to certain aspects of the question, but
> > we were all new once, we all have limited time to read things, and we
> > don't all learn perfectly reading general texts; sometimes we need our
> > specific question answered in order to understand a broader concept.
> > --
> > T.J. Crowder
> > Independent Software Engineer
> > tj / crowder software / com
> > www / crowder software / com
>
> > On Dec 16, 5:02 pm, bernard <bernard.christophe...@gmail.com> wrote:
>
> > > I truly wish some people would take the trouble to buy a javascript book
> > > instead of off-topic-posting in this group... meh.
> > > b.
>
> > > Intellectual honesty consists in taking ideas seriously. To take ideas 
> > > seriously means that you intend to live by, to practice, any idea you 
> > > accept as true.
> > > [Ayn Rand]

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to