I have function with loop and jQuery click function which I would like, after click, execute specific function. The a.id class is important, so like jQuery click definition. After click on element with specific id, I would like execute specific function. What can change is only function b?
var a = {
id: { "id1": function () { console.log(1) }, "id2": function () { console.log(2) }, "id3": function () { console.log(3) } },
b: function () {
$this = this;
for (v in $this.id) {
$("#" + v).click(function () {
$this.id[v]();
});
}
}
}
After i click on element, i want see id1 = 1, id2 = 2, id3 = 3
. But this code write value 3 for each element. This example is very simple. Problem is variable reference i know, but i can't find correct solution. Thanks