Returning event handler function
closeButton.onclick = (function(box){
return function(evt){box.display = 'none';};
})(msgBox);
I would like to return a function which will execute on the button click. 开发者_C百科Is this correct? If not, how it should be written?
Your example works and is using currying, but you could easily do without it. Since msgBox
is available in the current scope, you can reference it within the function which will create a closure for msgBox
.
closeButton.onclick = function(event) {
msgBox.display = 'none';
};
精彩评论