Re: IE leaks, circular references, addevent et al
- From: kangax <kangax@xxxxxxxxx>
- Date: Sat, 19 Sep 2009 15:56:33 -0400
David Mark wrote:
On Sep 18, 3:41 pm, kangax <kan...@xxxxxxxxx> wrote:[...]David Mark wrote:On Sep 17, 10:53 pm, kangax <kan...@xxxxxxxxx> wrote:David Mark wrote:On Sep 17, 10:18 pm, kangax <kan...@xxxxxxxxx> wrote:
I know. However, avoiding this practice seems to make things much harderFor example, `attachListener` delegates toYes and this is not a good practice.
`addNormalizedListener` which in turn calls `getTargetId` which then
assigns unique "uniqueID" to an element (if not yet present) via
`elementUniqueId` method.
(and some things - even impossible).
I recently stumbled upon a post by Zakas, where he gives a solution to
Who?
http://www.nczonline.net/
"Professional JavaScript" author
[...]
This is seemingly a more robust way. The downside here (and is my actual
point) is that if `iframe` element doesn't support "readystatechange"
event in some client, assignment to that "onreadystatechange" property
is essentially a host object augmentation. It's no different than
`iframe.foo = function(){ ... }` or `iframe._uniqueId = '_id12345'`.
Isn't it?
That's correct, but are you planning to use DOM0?
Well, obviously this is only an issue with using DOM0 (whether explicitly or if `addEvent` abstraction falls back to it after not finding anything better in some crippled clients).
My point is that "augmenting host object" has somewhat blurry definition. We all understand that assigning "_foobar" property to an element is not a good idea; yet we assign event handler properties not knowing whether client does in fact support corresponding events. For all we know, such property (e.g. `oncontextmenu`) can be no better that `_foobar` one and can lead to all the same consequences.
[...]
Understood.but IBecause I was avoiding expandos in IE by using their built-in unique
don't understand:
1) Why any target that has falsy `tagName` gets special treatment and is
injected with unique `"_api" + uniqueTargetHandle`
identifier, which doesn't work at all for document objects. All could
have been avoided, of course.
One thing you could do is use the DOM0 properties to stash the
normalized listeners (or a handle that points to them). Then you are
just augmenting a Function object.
Do you mean something along:
function f(){};
f._handlerId = _handlerId++;
someElement.onclick = f;
[...]
I don't think
having `addEvent` which behaves differently in W3C browsers and IE is a
good idea.
Why not? They goal is not to emulate addEventListener exactly, but to
provide an API for attaching and detaching listeners. None of this
really matters though as you can keep the duplicate detection in
without using expandos.
Yep. There's a fine range of ways to implement `addEvent` abstraction. Some features simply lead to more fragile implementation.
If we were to choose a particular set of traits for event handling
mechanism, than we might as well drop not only duplicate handling, but
`this` normalization too (which would prevent leaks handling in the
first place) :)
The leak problem has been solved a ways back and did not involve
expandos. Setting - this - is definitely a useful feature, but not
always needed. It always comes back to the context.
Yes, it always does.
[...]
and clearly it is because the design was trying to do too much.Determine that object is a `window`, then store it as a reference in
Surely there is a happy medium between that and requiring an ID for
every node (and how would that work for documents and windows anyway?)
array of such `window` objects? Later, that array can be iterated over
in order to determine `id` of a given `window` object.
Not sure if it's a good idea and how practical it is, though.
I wouldn't bother to write such a wrapper for window objects. ;)
Sure. Supporting multiple contexts is like supporting quirksmode or xhtml.
But tested on a variety of clients nevertheless, right?3) Whether you had any problems with all this host objects augmentationNot that I kmow of. Of course, I never used my library. ;) I do
in any environment.
Yes. By myself two years ago and many others since. Doesn't prove
much though. Expandos are still ill-advised.
If you're interested, I noticed that some things might fail in older Safari (e.g. 2.0) due to missing `compatMode` there, which seems to be used in `getContainerElement`. You need to feature test quirks mode when `compatMode` is missing (so that code doesn't erroneously fall into `body-acting-as-root` mode).
IIRC, one of the snippets in Cornford's "not browser detect" article uses `compatMode` without test as well.
[...]
--
kangax
.
- Follow-Ups:
- Re: IE leaks, circular references, addevent et al
- From: David Mark
- Re: IE leaks, circular references, addevent et al
- References:
- IE leaks, circular references, addevent et al
- From: Richard Maher
- Re: IE leaks, circular references, addevent et al
- From: abozhilov
- Re: IE leaks, circular references, addevent et al
- From: Richard Maher
- Re: IE leaks, circular references, addevent et al
- From: kangax
- Re: IE leaks, circular references, addevent et al
- From: David Mark
- Re: IE leaks, circular references, addevent et al
- From: kangax
- Re: IE leaks, circular references, addevent et al
- From: David Mark
- Re: IE leaks, circular references, addevent et al
- From: kangax
- Re: IE leaks, circular references, addevent et al
- From: David Mark
- Re: IE leaks, circular references, addevent et al
- From: kangax
- Re: IE leaks, circular references, addevent et al
- From: David Mark
- IE leaks, circular references, addevent et al
- Prev by Date: Re: Useful classical inheritance example?
- Next by Date: Re: Useful classical inheritance example?
- Previous by thread: Re: IE leaks, circular references, addevent et al
- Next by thread: Re: IE leaks, circular references, addevent et al
- Index(es):
Relevant Pages
|
Loading