diff options
author | Jason Bedard <jason+github@jbedard.ca> | 2015-08-23 14:23:35 -0700 |
---|---|---|
committer | Michał Gołębiowski <m.goleb@gmail.com> | 2015-09-08 01:55:51 +0200 |
commit | f5bf9bc48897e3b8f050d87d02252c8be456044a (patch) | |
tree | 80b11e122350bac949ca248f605c33c0fc92a587 | |
parent | 5adf04a73c135dc729b9d9889bc963b45a9fc471 (diff) | |
download | jquery-f5bf9bc48897e3b8f050d87d02252c8be456044a.tar.gz jquery-f5bf9bc48897e3b8f050d87d02252c8be456044a.zip |
Data: do not create data cache when fetching single property
Closes gh-2554
-rw-r--r-- | src/data/Data.js | 6 | ||||
-rw-r--r-- | test/unit/data.js | 16 |
2 files changed, 18 insertions, 4 deletions
diff --git a/src/data/Data.js b/src/data/Data.js index a19476ea6..e0d1eadcd 100644 --- a/src/data/Data.js +++ b/src/data/Data.js @@ -72,13 +72,11 @@ Data.prototype = { return cache; }, get: function( owner, key ) { - var cache = this.cache( owner ); - return key === undefined ? - cache : + this.cache( owner ) : // Always use camelCase key (gh-2257) - cache[ jQuery.camelCase( key ) ]; + owner[ this.expando ] && owner[ this.expando ][ jQuery.camelCase( key ) ]; }, access: function( owner, key, value ) { diff --git a/test/unit/data.js b/test/unit/data.js index bb66447f0..fc6b5723f 100644 --- a/test/unit/data.js +++ b/test/unit/data.js @@ -882,3 +882,19 @@ QUnit.test( "Check that the expando is removed when there's no more data", funct } } } ); + +QUnit.test( ".data(prop) does not create expando", function( assert ) { + assert.expect( 1 ); + + var key, + div = jQuery( "<div/>" ); + + div.data("foo"); + assert.equal( false, jQuery.hasData( div[0] ) ); + // Make sure no expando has been added + for ( key in div[ 0 ] ) { + if ( /^jQuery/.test( key ) ) { + assert.ok( false, "Expando was created on access" ); + } + } +} ); |