I am trying to figure out JavaScript OOP, I tried the following which works but fails when I need to make a change to a class variable on a specific instance.
I have "myname" with a default value, I then change it for a specific instance and in an event handler I print it's value. I get the default value and not the updated one.
how can I change the code to support this ?
thanks
function myClass () {}
myClass.prototype =
{
myname : "test",
test : function (filename)
{
var img = createSomething ();
img.container = this;
img.addEventListener('click', this.onClick);
},
onClick : function (e)
{
trace ("click: " + e.source.container.myname); // this will print "test" and not "dave"
}
};
var instance = new myClass ();
instance.myname = "dave";
instance.test();