为jquery插件实例创建唯一的id?

我创建了一个jQuery插件,它监听窗口的模糊事件。

我想在插件本身内部创建一个唯一的id,这样我就可以在销毁插件实例时关闭侦听器。 我该如何创建这些uniqueIds?

下面的示例显然不起作用 – destroy方法中的incrementId总是从上一个插件实例中删除模糊。

(function( $ ) { var incrementId = 0; var methods = { init : function( options ) { var that = this; incrementId += 1; $(window).on( "blur.pleaseKillMe" + incrementId, function( e ) { that.css( "color", "red" ); }); }, destroy : function( ) { console.log( "and... " + incrementId ); $(window).off( "blur.pleaseKillMe" + incrementId ); } }; $.fn.pleaseKillMe = function( method ) { if ( methods[method] ) { return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); } else if ( typeof method === 'object' || ! method ) { return methods.init.apply( this, arguments ); } else { $.error( 'Method ' + method + ' does not exist on jQuery.p5shrinkwrap' ); } }; })( jQuery ); 

 incrementId += 1; this.data('id', incrementId); ... $(window).off('blur.pleaseKillMe' + this.data('id');