Use .one() when doing a .bind() with an "unload" event type (#1242)

This commit is contained in:
Brandon Aaron 2007-05-31 00:13:54 +00:00
parent ee31297a83
commit d85a22a70e

View file

@ -250,6 +250,9 @@ jQuery.fn.extend({
* data as the second parameter (and the handler function as the third), see * data as the second parameter (and the handler function as the third), see
* second example. * second example.
* *
* Calling bind with an event type of "unload" will automatically
* use the one method instead of bind to prevent memory leaks.
*
* @example $("p").bind("click", function(){ * @example $("p").bind("click", function(){
* alert( $(this).text() ); * alert( $(this).text() );
* }); * });
@ -286,7 +289,7 @@ jQuery.fn.extend({
* @cat Events * @cat Events
*/ */
bind: function( type, data, fn ) { bind: function( type, data, fn ) {
return this.each(function(){ return type == "unload" ? this.one(type, data, fn) : this.each(function(){
jQuery.event.add( this, type, fn || data, fn && data ); jQuery.event.add( this, type, fn || data, fn && data );
}); });
}, },