Search

12/28/2008

JavaScript timers - using functions and scope

JavaScript timers - using functions and scope - Robert’s talk - Web development and Internet trends
setElmBGColor function - using a function and scope


function setElmBGColor (bgColor) {
var currentElm = this;
setTimeout(function () {
currentElm.style.backgroundColor = bgColor;
}, 1000);
}

setElmBGColor function - using a function with scope and closure

function setElmBGColor (bgColor) {
setTimeout(function (elm) {
return function () {
elm.style.backgroundColor = bgColor;
};
}(this), 1000);
}

沒有留言: