function Cons(name) {
var pvar1="hi "+name;
sayhi = function() {
alert(pvar1);
}
attEvents(){
$('#'+name).bind("click",sayhi);
}
}
var a = new Cons('name1');
var b = new Cons('name2');
var c = new Cons('name3');
Let us assume that name1, name2, name3 are all divs. Now, whatever div I click, I am always getting "hi name3". The private variable is having the last stored value in it irrespective of the div clicked. Any help is appreciated.
Thanks
sayhiis global and.bind("click",sayhi);is called some time after the three objects have been created. But to know for sure you would have to correct/clarify this statement:attEvents(){ $('#'+name).bind("click",sayhi);}What is it doing?