Skip to content

Commit f5bf9bc

Browse files
jbedardmgol
authored andcommitted
Data: do not create data cache when fetching single property
Closes gh-2554
1 parent 5adf04a commit f5bf9bc

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/data/Data.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,11 @@ Data.prototype = {
7272
return cache;
7373
},
7474
get: function( owner, key ) {
75-
var cache = this.cache( owner );
76-
7775
return key === undefined ?
78-
cache :
76+
this.cache( owner ) :
7977

8078
// Always use camelCase key (gh-2257)
81-
cache[ jQuery.camelCase( key ) ];
79+
owner[ this.expando ] && owner[ this.expando ][ jQuery.camelCase( key ) ];
8280
},
8381
access: function( owner, key, value ) {
8482

test/unit/data.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,3 +882,19 @@ QUnit.test( "Check that the expando is removed when there's no more data", funct
882882
}
883883
}
884884
} );
885+
886+
QUnit.test( ".data(prop) does not create expando", function( assert ) {
887+
assert.expect( 1 );
888+
889+
var key,
890+
div = jQuery( "<div/>" );
891+
892+
div.data("foo");
893+
assert.equal( false, jQuery.hasData( div[0] ) );
894+
// Make sure no expando has been added
895+
for ( key in div[ 0 ] ) {
896+
if ( /^jQuery/.test( key ) ) {
897+
assert.ok( false, "Expando was created on access" );
898+
}
899+
}
900+
} );

0 commit comments

Comments
 (0)