Why is the Element::store() not listed in the documentation??? http://www.prototypejs.org/api/element .
Thanks for pointing out this feature. I've been stupidly creating my own data structures to further describe DOM elements. Now I don't have to do that. On Nov 22, 12:31 pm, Luke <[email protected]> wrote: > Thank you Mr Crowder, that was quite informative. > > Still I'm a little unsure how to proceed. If I got this right, it is > common sense now that extending the DOM is the wrong thing to do. One > of the main reasons is the possibility of name-conflicts. So I thought > I might extend Objects with a JSON-Object (called 'builder' in my > case) which contains all my methods and properties to (sort of) have > my own namespace. But that would require a circular reference in my > builder-object to the DOM-Element it is attached to (so the methods in > my builder-object can work on the DOM they are attached to). > > I'm wondering if there's any way to keep that nice programming- > paradigm prototype introduced with it's $-function, that you can > simply write $('myelement').myfunction() while avoiding the above- > mentioned problems. I could write my own wrapper-method, like jQuery's > $-function, but that would miss the whole point of working with > prototype. > > How do other people work with this? > > Luke > > On Nov 22, 7:37 am, "T.J. Crowder" <[email protected]> wrote: > > > Hi Luke, > > > What you're talking about doing is called an "expando" property. > > They're not covered by a standard AFAIK, although interestingly > > Microsoft has an `expando` property on objects[1] (this is where the > > name came from) which is a boolean saying whether you can do this. If > > you do a web search on "expando" you'll find a lot more information > > (and a studio album by Timothy B. Schmit, but leave that aside...). > > (Ignore the statement on GreaseSpot that expandos relate to custom > > attributes; they don't, the article is just wrong.) > > > Prototype uses expando properties like mad (the whole concept of > > "extending" an element[2] relies on expandos, and Prototype uses them > > elsewhere as well), so if you're using Prototype, you're already > > relying on the environment allowing expandos. But it's probably worth > > noting that Prototype is moving away from expandos at some point in > > favor of doing a jQuery-like wrapper thing instead. > > > I'd avoid having your expando property value (directly or indirectly) > > reference another DOM element, as that sets up the possibility of > > circular references, and circular references that dip between the DOM > > and JavaScript layers can cause memory leaks on IE. > > > [1]http://msdn.microsoft.com/en-us/library/ms533747(VS.85).aspx > > [2]http://prototypejs.org/learn/extensions > > > Happy coding, > > -- > > T.J. Crowder > > Independent Software Engineer > > tj / crowder software / com > > www / crowder software / com > > > On Nov 21, 8:28 pm, Luke <[email protected]> wrote: > > > > Thanks Walter. If that's the only reason I'm willing to take that > > > risk. In my whole application I will only attach one variable, kind of > > > like my namespace and this will give me some convenience when > > > accessing that namespace. If it's conform to W3C standards and works > > > in all browsers, I think it's ok. But is it? Can't find any > > > documentation or specification on this > > > > Luke > > > > On Nov 21, 8:50 pm, Walter Lee Davis <[email protected]> wrote: > > > > > I think that the basic reason for the separate store is to provide > > > > insulation from any current, past, or future browsers tramping on a > > > > key name you may choose today and test in some subset of all browsers. > > > > Browser scripting is fun enough in IE with its amusing conflation of > > > > Name and ID properties without getting into the weeds with a perfectly- > > > > safe-seeming data element being confused for some completely other > > > > property or method. > > > > > Walter > > > > > On Nov 21, 2010, at 2:15 PM, Luke wrote: > > > > > > Hi, > > > > > > is there anyting wrong with extending a DOM-Object with > > > > > > $('myelement').myvariable = "something"; > > > > > > or why is there the prototype-method store, which saves values in a > > > > > seperate hash? > > > > > > Thank you, > > > > > Lukas > > > > > > -- > > > > > 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 > > > > > athttp://groups.google.com/group/prototype-scriptaculous?hl=en > > > > > . -- 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.
