On Jul 2, 11:43 am, Antoine Quint <[EMAIL PROTECTED]> wrote:
> On Jul 2, 2008, at 17:27 , Ryan Gahl wrote:
>
> > Nowhere on that page does it say that static class methods are
> > copied to the prototype.
>
> I think there are only ever static class methods passed in
> Class.create(). When you do this:
>
> Class.create({
> initialize: function() {
> // some code here
> }
>
> });
>
> you are passing Class.create an anonymous object with a single static
> method defined on it. That object could not be used to create a class
There are no "static" or "instance" methods on js objects really : )
I understand what you mean, but it just sounds confusing.
> with the "new" construct, it has no constructor to speak of. That's
> the whole premise of Class.create as I understand it, you pass it an
> anonymous object which really is just a class definition.
>
> The style I use to create classes with Class.create is to actually
> name that anonymous object, define what will be instance methods as
> static methods on it, pass that object to Class.create() and update
> the object with what is returned. So what I wrote above is rewritten
> that way and is equivalent as I understand it.
>
> MyClass = {};
>
> MyClass.initialize = function () {
> // some code here
>
> };
>
> MyClass = Class.create(MyClass);
>
I've never seen such way of defining "classes". It seems weird to
first create a reference to an empty object literal, then redefine it
to point to a "class" definition. Whatever works for you.
> > If, for whatever reason, it actually IS supposed to work that way,
> > it's a major flaw, and should be fixed immediately. But like I said,
> > it wouldn't make any sense if it worked like that, and so it doesn't.
>
> I think it's a pretty elegant design and it's actually the reason I
> chose Prototype as a base framework, because I really liked how it
> lets one define classes.
>
Prototype doesn't provide any special facility for defining "static"
members (as majority defines it). All it takes is to declare them as
members of "class" function.
var Foo = Class.create({ ... })
Foo.blah = 'my static property';
> > So, with that - just do what darrin suggests (which is the best way
> > to ensure your instance methods are truly instance only methods)...
> > or attach them directly to the prototype object after Class.create()
> > is called.
>
> I think I'll just have a special method called in .initialize that
> will map the getters and setters automatically. I was just hoping that
> Prototype might already have a way to deal with JS getters and setters
> outside of the constructor.
>
You could do that, though "fat" constructors is usually not a good
idea. It would also cripple performance if constructor is called
frequently.
-- kangax
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to rubyonrails-spinoffs@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---