On Feb 8, 7:59 pm, Alexander Presber <[EMAIL PROTECTED]> wrote:
> > With prototype-based inheritance they all point to
> > the same copy. It's a big win for memory usage. Read this interview
> > with Dean Edwards:http://snook.ca/archives/writing/an_interview_wi/
> I see your point. But this is not exactly what happens here.
> We do indeed save memory by putting the methods into the Hashes
> I completely missed that and it is indeed an advantage.
> not copying Enumerables methods into our constructor, but
> putting Enumerable into our prototype chain. This saves even more
> memory (no copying of any methods to extended classes, leave alone
> instances) and leaves Enumerable "open", which means we can still
> override Enumerables methods and add new ones, even on instantiated
Yes, what you're describing would be ideal, but play around with it
for just a few minutes in FireBug and you'll realize it can't be done.
There's no way to slip an arbitrary object into the prototype chain of
a builtin, so the only alternative is to copy Enumerable over to
Array.prototype via Object.extend.
Now, custom objects like Hash are a different matter. But I think
it's better to be consistent. If redefining Enumerable.reject updated
Hash.prototype.reject and ObjectRange.prototype.reject but not
Array.prototype.reject, then that'd be confusing. Also, the principle
of least surprise dictates that we adhere to Ruby conventions whenever
possible. In Ruby, Enumerable is a mixin, not a class. Better, then,
to use Object.extend (which functions like a mixin) than to have
objects inherit from Enumerable.
> How is the state of affairs in introducing Dean Edwards Base
> inheritance to prototype? There are some tickets on inheritance, but
> one especially for that?
It's a stated goal for 2.0; I'd love to get it into the codebase even
sooner. I think it'd take until 2.0 to rewrite the existing classes
(Ajax.*, for instance) to follow a proper inheritance model, but that
doesn't mean we have to wait until 2.0 to introduce something Base-
like. Ultimately it's up to Sam, though.
You received this message because you are subscribed to the Google Groups
"Prototype: Core" group.
To post to this group, send email to firstname.lastname@example.org
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at