mirror of
https://github.com/jquery/jquery.git
synced 2026-02-15 18:24:55 -05:00
Avoid side-effects when calling jQuery.hasData
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
This commit is contained in:
10
src/data.js
10
src/data.js
@@ -21,11 +21,17 @@ function Data() {
|
||||
Data.uid = 1;
|
||||
|
||||
Data.prototype = {
|
||||
key: function( owner ) {
|
||||
key: function( owner, options ) {
|
||||
var descriptor = {},
|
||||
// Check if the owner object already has a cache key
|
||||
unlock = owner[ this.expando ];
|
||||
|
||||
// `readonly` calls from hasData, on owners with no key
|
||||
// should not create new/empty cache records
|
||||
if ( !unlock && (options && options.readonly) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// If not, create one
|
||||
if ( !unlock ) {
|
||||
unlock = Data.uid++;
|
||||
@@ -158,7 +164,7 @@ Data.prototype = {
|
||||
},
|
||||
hasData: function( owner ) {
|
||||
return !jQuery.isEmptyObject(
|
||||
this.cache[ this.key( owner ) ]
|
||||
this.cache[ this.key( owner, { readonly: true }) ] || {}
|
||||
);
|
||||
},
|
||||
discard: function( owner ) {
|
||||
|
||||
Reference in New Issue
Block a user