Hi,

On Oct 20, 3:33 am, buda <[email protected]> wrote:
> T.J. here is the example of using instance private vaiables store in use 
> -http://jsfiddle.net/QW8vM/17/

FWIW, that code refers to an undefined symbol `_items` in the property
getter function. Also note that it has a memory leak: `destroy`
releases the `items` on the private variables object you create for
every instance, but doesn't actually release the private variables
object itself or the array entry associated with it. So every instance
creation/destruction will leak a small amount of memory and as time
goes by, the array will get more and more bogged down in abandoned
entries.

Here's a version without those issues (note that `_privates` is now
just an object, not an array, and see also changes in `destroy`):
http://jsbin.com/ewoniq

Unless you're going to have lots and lots of these objects in memory
at the same time (like, thousands), I'd *strongly recommend* you avoid
this pattern. Instead, just define `add` and `indexOf` within
`initialize` and have them use `_items` (the local var in
`initialize`) directly. This increases the overhead per instance
(because each and every instance gets its own `add` and `indexOf`
functions), but avoids requiring the `destroy` call. Example:
http://jsbin.com/ewoniq/2

FWIW,
--
T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to