Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit d85a22a70ead4a3a22bf1eebe05d08b498f70aa1 1 parent ee31297
@brandonaaron brandonaaron authored
Showing with 4 additions and 1 deletion.
  1. +4 −1 src/event/event.js
View
5 src/event/event.js
@@ -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() );
* });
@@ -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 );
});
},
Please sign in to comment.
Something went wrong with that request. Please try again.