[whatwg] Scripting Tweaks
liorean
liorean at gmail.com
Fri May 18 22:14:11 PDT 2007
On 19/05/07, Ian Hickson <ian at hixie.ch> wrote:
> > 3) I find myself using Microsoft's uniqueID property quite often. Although the
> > ID attribute is supposed to provide a unique identifier, it often doesn't. We
> > would probably need a complementary DOM method to retrieve an element by
> > uniqueID (IE uses the "all" property).
> >
> > http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/uniqueid.asp
> >
> > If I want to build a list of elements that I've already processed:
> >
> > var processed = {};
> > for (var i in elements) {
> > if (!processed[elements[i].uniqueID]) {
> > process(elements[i]);
> > processed[elements[i].uniqueID] = true;
> > }
> > }
> >
> > I can't think of another way of doing that.
>
> for (var i in elements) {
> if (!elements[i].processed) {
> process(elements[i]);
> elements[i].processed = true;
> }
> }
> for (var i in elements)
> delete elements[i].processed;
>
> The "uniqueID" thing is really working around a deficiency in JS
> (inability to use objects as keys). I think that's where it should be
> addressed. The uniqueID idea has a number of rather unique implementation
> difficulties. The obvious implementations have security and privacy
> implementations; the solutions to those tend to be expensive either in RAM
> or CPU. I recommend bringing this to the attention of the ES4 group.
ES4 already has something of the kind. See
<uri:http://developer.mozilla.org/es4/proposals/hashcodes.html>
However, that is not usable in ES3 implementations, which uniqueID is.
Besides, the problem is solvable without polluting the objects by
adding property through using one object for storing processed
elements and one object for the full set of elements. Then you can use
something like
processed_elements[key]=all_elements[key];
for storing that an element is processed,
delete processed_elements[key];
to remove an element from the processed elements list, and something like
for(key in all_elements)
if(!(processed_elements.hasOwnProperty(key)))
process(key);
to iterate through the unprocessed elements.
--
David "liorean" Andersson
More information about the whatwg
mailing list