diff options
author | Brandon Aaron <brandon.aaron@gmail.com> | 2007-05-31 00:13:54 +0000 |
---|---|---|
committer | Brandon Aaron <brandon.aaron@gmail.com> | 2007-05-31 00:13:54 +0000 |
commit | d85a22a70ead4a3a22bf1eebe05d08b498f70aa1 (patch) | |
tree | 2b4a150b907e8fa432691de6dea2fa49ae6070d8 | |
parent | ee31297a83f3add9f1832e863da3b6100ab9e7d3 (diff) | |
download | jquery-d85a22a70ead4a3a22bf1eebe05d08b498f70aa1.tar.gz jquery-d85a22a70ead4a3a22bf1eebe05d08b498f70aa1.zip |
Use .one() when doing a .bind() with an "unload" event type (#1242)
-rw-r--r-- | src/event/event.js | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/event/event.js b/src/event/event.js index 77a404648..a1a0825dc 100644 --- a/src/event/event.js +++ b/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 ); }); }, |