开发者

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';
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜