javascript - How to unsubscribe from events without disrupting other instances of the same plugin? -
i have created jquery plugin needs respond resizing of browser window. subscribes event using jquery's event namespacing mechanism:
var $window = $(window); $window.on("resize.myplugin", function(e) { // resize code });
so when plugin destroyed, can gracefully unsubscribe without disrupting other plugins:
$window.off("resize.myplugin");
however, in case, happens if have multiple instances of same plugin @ same time? calling off
above unsubscribe event handlers because use same namespace.
how can unsubscribe events without disrupting other instances of same plugin?
if expect other instances of same plugin coexist, can prefix events random namespace, avoiding disconnecting of them.
edit: posting mobile, took time writing. :)
Comments
Post a Comment