This project is archived and is in readonly mode.

#873 ✓invalid
batman42ca

Hash declared in a class definition is shared between class instances

Reported by batman42ca | March 20th, 2010 @ 10:00 PM

When I declare a Hash like this inside my class:

var MyObj = new Class({
  myHash : new Hash()
});

All instances of MyObj share the same Hash.

see this for a working example:

http://mootools.net/shell/ztNXe/

This came as a BIG surprise (after a few hours of debugging)

Comments and changes to this ticket

  • Fábio M. Costa

    Fábio M. Costa March 21st, 2010 @ 07:26 PM

    This is the correct behavior.

    If you wish to have a different hash at each instance you can do this:

    var MyObj = new Class({
      initialize: function(){
        this.myHash = new Hash();
      }
    });
    

    each instance of MyObj will have a new, different, Hash object.

  • Fábio M. Costa

    Fábio M. Costa March 27th, 2010 @ 08:45 PM

    • State changed from “new” to “invalid”

    ill mark as invalid but dont think i'm mad at you ok? ;)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

People watching this ticket

Referenced by

Pages