diff options
author | Timmy Willison <timmywillisn@gmail.com> | 2015-05-06 15:29:06 -0700 |
---|---|---|
committer | Timmy Willison <timmywillisn@gmail.com> | 2015-05-12 10:09:40 -0400 |
commit | 56bb677725b21415905e5c3eeb1e05be4480e780 (patch) | |
tree | 6ea93a20973e78f466412eeb58957af7e9075bdf /src | |
parent | 764dc949d0d65742606747ce75852d1b5dd59fcd (diff) | |
download | jquery-56bb677725b21415905e5c3eeb1e05be4480e780.tar.gz jquery-56bb677725b21415905e5c3eeb1e05be4480e780.zip |
Data: remove the expando when there's no more data
Fixes gh-1760
Close gh-2271
Diffstat (limited to 'src')
-rw-r--r-- | src/data/Data.js | 10 | ||||
-rw-r--r-- | src/event.js | 9 |
2 files changed, 8 insertions, 11 deletions
diff --git a/src/data/Data.js b/src/data/Data.js index d56e37839..5268f3f2c 100644 --- a/src/data/Data.js +++ b/src/data/Data.js @@ -120,10 +120,7 @@ Data.prototype = { return; } - if ( key === undefined ) { - this.register( owner ); - - } else { + if ( key !== undefined ) { // Support array or space separated string of keys if ( jQuery.isArray( key ) ) { @@ -147,6 +144,11 @@ Data.prototype = { delete cache[ key[ i ] ]; } } + + // Remove the expando if there's no more data + if ( key === undefined || jQuery.isEmptyObject( cache ) ) { + delete owner[ this.expando ]; + } }, hasData: function( owner ) { var cache = owner[ this.expando ]; diff --git a/src/event.js b/src/event.js index b371b9a27..584ba9073 100644 --- a/src/event.js +++ b/src/event.js @@ -216,14 +216,9 @@ jQuery.event = { } } - // Remove the expando if it's no longer used + // Remove data and the expando if it's no longer used if ( jQuery.isEmptyObject( events ) ) { - // Normally this should go through the data api - // but since event.js owns these properties, - // this exception is made for the sake of optimizing - // the operation. - delete elemData.handle; - delete elemData.events; + dataPriv.remove( elem, "handle events" ); } }, |