Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use .one() when doing a .bind() with an "unload" event type (#1242)
  • Loading branch information
brandonaaron committed May 31, 2007
1 parent ee31297 commit d85a22a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/event/event.js
Expand Up @@ -250,6 +250,9 @@ jQuery.fn.extend({
* data as the second parameter (and the handler function as the third), see
* 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(){
* alert( $(this).text() );
* });
Expand Down Expand Up @@ -286,7 +289,7 @@ jQuery.fn.extend({
* @cat Events
*/
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 );
});
},
Expand Down

0 comments on commit d85a22a

Please sign in to comment.