R
Robert
Hi,
I don't really have a problem, but I would like to know what is
happening when using function literals for events.
For example:
var obj = {value: 5};
var val = obj.value;
button.onclick = function()
{
alert(obj.value);
alert(val);
}
Clicking will display 5 and 5 of course.
If some script later will do
obj.value++;
the clicking will display 6 and 5.
Could someone tell me how 'obj.value' and 'val' are resolved in the
function literal?
I have some ideas... but like to be sure. Because I keep feeling
insecure when using function literals
I don't really have a problem, but I would like to know what is
happening when using function literals for events.
For example:
var obj = {value: 5};
var val = obj.value;
button.onclick = function()
{
alert(obj.value);
alert(val);
}
Clicking will display 5 and 5 of course.
If some script later will do
obj.value++;
the clicking will display 6 and 5.
Could someone tell me how 'obj.value' and 'val' are resolved in the
function literal?
I have some ideas... but like to be sure. Because I keep feeling
insecure when using function literals