Some downsides to using expandos (arbitrary attribute key/value pairs on
DOMElements):

1) possible memory leaks
2) keyname choice is limited because of built in attributes/properties
3) have to be careful about what you stick in there (see 1). Best to stick
with simple values, ints and strings

jQuery solves these by putting at most 1 expando on each element. The value
is an int, so it's safe from memory leaks. The attribute key is prefixed
with 'jquery' so there's no naming collision. Then the object store/cache is
completely external to the DOMElement itself. It's as easy to use as
.attr(); just substitute .data().

- Richard

On Wed, Aug 27, 2008 at 11:05 AM, Paul Carey <[EMAIL PROTECTED]> wrote:

>
> Hi
>
> I've been setting arbitrary attributes on my html tags, and using
> jQuery to make AJAX requests based on their values. These has worked
> well so far as writing out arbitrary attributes from the backend is
> trivial.
>
> But I'm about to start using per element attributes more intensively,
> and now I'm questioning my approach. I'm aware that jQuery UI makes
> heavy use of the data cache and I assume it does so with good reason.
>
> At what point does it make more sense to use the data cache rather
> than just set html attributes? I'm thinking when closures or rich
> JavaScript objects are required? If my needs are met by key / value
> pairs are there any downsides to arbitrary attributes that I should be
> aware of?
>
> Many thanks
>
> Paul
>

Reply via email to