abozhilov said:
error-prone? Where error-prone in that example? attachEvent itself
produce error only if pass handler who isn't referred to `object'.
You are (needlessly) accessing the property of an object before you have
made sure that there is an object to begin with, an inherently error-prone
design pattern that I have coined a reference worm[tm].
You also overlooked the "inefficient" part. It is very inefficient to call
a method, on every occurence of an event, in order to return a reference to
an object that one has already stored elsewhere in a readily available
fashion. And that approach would hardly be simplifying the example for
better understanding.
I don't understand what are you mean with this expression. Maybe
ironic?
Not at all.
But in your latest post, example with closure handler, again
needs from breaking circular reference. Whatever.
AFAIK it is the polite way of saying "I did not understand what you were
saying or why" in formal English, the question mark emphasizing the
politeness. Synonyms are "Excuse me?" or "(I'm) sorry?". Compare
"извините" in Russian, or, as you appear to post from Bulgaria, probably
"извинете" in Bulgarian.
(Maybe you should learn the *basics* of the English language before
discussing in English?)
Please excuse me. Before parsing all page, you don't need handler.
But you do. It is unwise at best to assume that a document will not be
displayed and accessible by the user before it was completely loaded (with
a rather wide margin about what "loaded" really means -- does that include
all referred resources, e.g. images, or not? -- even current browser vendors
do not agree on a definition). Incremental rendering is prevalent these days.
What if the user accesses the already displayed element while the document
is loading? Granted, with a `change' event that may not be as likely
(although entirely possible), but what about a `click' event? We have
discussed the unwanted change in behavior of the user interface depending on
the loading state here before.
What are you thing about the case when, that handler related with
element who is down in the DOM tree? That error will be hard to
debugging.
It will not, for the erroneous method can be tracked down in the markup,
where its identifier is included verbatim, per element (and its ancestor
elements, if the event happens to be a bubbling one).
And adding listeners dynamically will help nothing to avoid a perceived, but
non-existing problem; instead, it will add more problems, such as a not
future-proof dependency on a certain subset of (currently known) DOMs. By
comparison, event-handler attributes have worked ever since client-side
scripting was introduced, everywhere where script support was present, and
are going to continue to work there and then regardless of changes in the
ways in which event listeners may be added.
Granted, there are instances where adding event listeners dynamically is
preferable, such as non-bubbling events that need to be handled on a large
number of elements. However, in all other cases the standards-compliant
*and* most compatible approach should be followed, which are event-handler
attributes.
And any mixing like this is hard to hold clear application.
Quite the contrary. With event-handler attributes, one knows which element
does what and when at a glance. With the so-called (but misnamed)
unobtrusive approach you have to look for the element by ID or whatever, and
even then you cannot be sure that it does what it is supposed to do as you
are dealing with a host object that it is represented by. Especially the
addEventListener() and addEvent() approaches are comparably hard to debug
because no debugging tool so far lists them on inspection of an element (not
even Firebug; while it has the Log Events feature, that requires the event
to occur -- so to be caused by the developer -- first).
What are you thing about the case, where html code is complete same in
any template. Only you can change behaviour and presentation of
application?
I would submit that if the very same markup would produce a user interface
that behaved differently, something would be terribly wrong with the
application's user interface design.
PointedEars