Javascript: outside variable used inside closure -


i have simple jquery popup plugin. usage looks this:

$("#popupcontainer").popup({     onopen: function () { },     onclose: function () { } }); $("#popupcontainer").popup("open", "/home/popupcontent"); $("#popupcontainer").popup("close"); 

this works good.

however, want pass different onopen callback different url's have. thought making wrapper on plugin, this:

var popupplugin = {}; (function () {     var onopen = null;     var onclose = null;      $("#popupcontainer").popup({         onopen: function () {             if (onopen) {                 onopen();             }             onopen = null;         },         onclose: function () {             if (onclose) {                 onclose();             }             onclose = null;         }     });      popupplugin.open = function (url, callback) {         onopen = callback;         $("#popupcontainer").popup("open", url);     }     popupplugin.close = function (callback) {         onclose = callback;         $("#popupcontainer").popup("close");     } }());  // usage popupplugin.open("/home/popupcontent", function () {     // specific callback }); 

this works expected (i have different callbacks), worried creating memory leaks somehow.

is implementation of popupplugin wrapper good?


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -