]> source.dussan.org Git - jquery.git/commitdiff
Data: do not create data cache when fetching single property
authorJason Bedard <jason+github@jbedard.ca>
Sun, 23 Aug 2015 21:23:35 +0000 (14:23 -0700)
committerMichał Gołębiowski <m.goleb@gmail.com>
Mon, 7 Sep 2015 23:55:51 +0000 (01:55 +0200)
Closes gh-2554

src/data/Data.js
test/unit/data.js

index a19476ea6c0a1c24d636c2e1bf962fb03303e126..e0d1eadcd9f4f64f51544e751472320c97778846 100644 (file)
@@ -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 ) {
 
index bb66447f076d4ffbcf6855ba3ed3aae0e37a091f..fc6b5723fa54f54648ed96a65f5038f88c297652 100644 (file)
@@ -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" );
+               }
+       }
+} );