On Feb 8, 6:26 pm, Alexander Presber <[EMAIL PROTECTED]> wrote:
> Now my question is: What is the advantage of the new Hash
> implementation? Why did Class.create not suffice? I can see added
> complexity but no real gain, since Enumerable is not really in the
> prototype chain of Hash, its methods are just copied to the Hashes
> prototype.
The advantage is the reason that prototypes exist in JavaScript in the
first place. Using the previous method (copying methods onto each
instance), if you create 100 you've got to make 100 copies of your
inherited methods. 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/
That said, if you need to redefine Enumerable methods I don't think
it's that much of an inconvenience to do:
Enumerable.findAll =
Array.prototype.findAll =
ObjectRange.prototype.findAll =
Hash.prototype.findAll = function() { /* ... */ }
It's certainly not pretty, but you could roll it up into some sort of
function if you're redefining Enumerable methods that often.
More to the point: why override Enumerable methods when you can define
new ones -- "customFindAll" or "_reject" or something like that?
Seems more future-proof and friendlier to other scripts.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype: Core" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---