hello, I am trying to apply a method to an existing object which involves using its private variables. The object is setup like so:
function a(given_id)
{
var id= given_id;
}
now I want to apply some new method to it like so
my_obj = new a('some_id');
my_obj.myMethod = function(){
alert(id);
}
now if I go my_obj.myMethod() I get an error saying id is undefined. This same code works if I change id from being private to public.
I don't understand why this is happening because if myMethod was defined originally in a as a privileged method it would work. The only thing I can think of is that myMethod is being added as a public method, instead of a privileged one.
Any information on this would be much appreciated.