On Oct 21, 3:39 am, chrysanthe m <chrysant...@gmail.com> wrote:
> Hello
> How do I clear a prototype hash?  I have finally tried and failed with below
> after trying hashBrown.length=0 and hashBrown.clear().
>   hashBown.each(function(key) {
>         hashBrown.unset(key);
>       });

I'm surprised the loop didn't work, it seems to:

Or you could add your own `clear` function, but you'd want to be sure
to check with each Prototype dot release that the implementation
didn't need to be tweaked:

* * * *
// Add Hash#clear
// Note that this must be RECHECKED on every Prototype dot release
// to ensure that the internals haven't changed.
(function() {
  function Hash_clear() {
    this._object = {};

  Hash.prototype.clear = Hash_clear;
* * * *

I would _not_ suggest just doing hashBrown._object = {}; inline in
your code. Define a method and check the implementation on every dot
release, so there's only one place to add it.

I _know_ I've seen discussion of adding a #clear method to hash, but I
don't recall the result. As it's not in 1.7, maybe someone thought it
wasn't a good idea, but it seems like an odd omission to me. I've done
a ticket in Lighthouse[1] offering to do a patch on git (for 1.7.1,
not 1.7.0) if people do want it.


T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com

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 
For more options, visit this group at 

Reply via email to