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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -