1
1
var expando = "jQuery" + now ( ) , uuid = 0 , windowData = { } ;
2
+ var emptyObject = { } ;
2
3
3
4
jQuery . extend ( {
4
5
cache : { } ,
@@ -10,24 +11,28 @@ jQuery.extend({
10
11
windowData :
11
12
elem ;
12
13
13
- var id = elem [ expando ] , cache = jQuery . cache ;
14
+ var id = elem [ expando ] , cache = jQuery . cache , thisCache ;
14
15
15
16
// Compute a unique ID for the element
16
17
if ( ! id ) id = elem [ expando ] = ++ uuid ;
17
18
18
- // Only generate the data cache if we're
19
- // trying to access or manipulate it
20
- if ( name && ! cache [ id ] )
21
- cache [ id ] = { } ;
22
-
23
- var thisCache = cache [ id ] ;
19
+ // Handle the case where there's no name immediately
20
+ if ( ! name ) { return id ; }
24
21
22
+ // Avoid generating a new cache unless none exists and we
23
+ // want to manipulate it.
24
+ if ( cache [ id ] )
25
+ thisCache = cache [ id ] ;
26
+ else if ( typeof data === "undefined" )
27
+ thisCache = emptyObject ;
28
+ else
29
+ thisCache = cache [ id ] = { } ;
30
+
25
31
// Prevent overriding the named cache with undefined values
26
32
if ( data !== undefined ) thisCache [ name ] = data ;
27
33
28
34
if ( name === true ) return thisCache ;
29
- else if ( name ) return thisCache [ name ] ;
30
- else return id ;
35
+ else return thisCache [ name ] ;
31
36
} ,
32
37
33
38
removeData : function ( elem , name ) {
0 commit comments