"Richard Cornford" <Richard@litotes.demon.co.uk> wrote in message news:<cc1bc9$4ff$1$8302bc10@news.demon.co.uk>...
Great stuff, it is quite another style of programming and it may take
a moment to become familiar with it, but i think that i have
understood the main things. Otherwise i will ask again...
[color=blue]
> One of the questions in OO design is to determine the best demarcation
> between the objects used. Wanting a facility for any
> instance of any class (we can accept the OO terminology here as a
> convenient shorthand for broadly analogous concepts) to attach a
> listener, that may be a method of a specific object, to any event
> handler on any DOM element, means that the classes using the
> facility should not have any interest in the implementation of the
> facility; it should be a simple common interface that is globally
> available when needed.
>
> In your original code you are trying to handle both callback functions
> and calling methods on specific object instances. Overall I think these
> two activities can (and so probably should) be separated. That is, I
> would want the interface to the event handlers to be interested in
> callback functions and have a separate mechanism that allowed the
> callback functions to call methods on associated object instances. That
> will involve wrapping the object instance and methods to call
> information in a closure that returned a function that would then act as
> the callback function.[/color]
The reason why i was trying to handle both things in the same method
is that i would like to keep it simple for the end user. The code here
is acting as a basic library, that means that there will (hopefully)
be a few people using it. So i tend to solve the problem with a
all-in-one solution, the perfect thing would be if the call could be
done with something like that:
[XHTMLElementInstance].addEventlistener("event",function_reference);
[color=blue]
> One of the main reasons that I would choose this separation is that it
> would make it relatively easy for the event listener handling
> implementation to employ the DOM Events - add/removeEventListener - as
> its primary mechanism and only use the intrinsic event handlers as a
> fall-back. Allowing the intrinsic event aspects of the code to be
> dropped entirely in the future if DOM Events becomes universally
> supported in browsers in use, without the need to modify any of the code
> for the classes using the facility. For that reason I will also be using
> the shorter event names, without the 'on' prefix, in discussing the
> interfaces. However, I will not actually employ -
> add/removeEnventListener - in any of the following code.[/color]
The application is just avalaible for DOM-compatible Browser so i
could use add/removeEventListener.
[color=blue]
> Using a Java style public constructor-less class with public static
> methods forming the interface seems like a reasonable implementation. So
> a global variable named - EventHandling - (or as you like it) will have
> the methods - addListner - and - removeListener -, and each method will
> expect the arguments - domElement -, - eventName - and - callBackFnc -.
> eventName being the short form without the 'on' prefix.
>
> (Incidentally, there is no way that your original code should have been
> creating a DOM element when it was not passed one by reference. That
> gave you HTMLElement object an extremely strange duel role.)[/color]
Well normally it does create DOM elements but i didn't want to include
that in my example. In fact we start with a blank page an then we
start to add DOM elements. For better understanding you may visit
http://free.pages.at/giftzwerg/webos0.1/webos.html
I know it's bad coding-style and there are many bugs, but until now I
didn't have the time to correct it and to wirte it better...
<snipped out really good stuff>
[color=blue]
> If the system was intended to be used exclusively, or mostly, to call
> instance methods then it might make a lot as sense to have the -
> associateObjInstanceMethodWithCallBackFunction - function on the -
> EventHandling - interface.[/color]
Yes i think it makes sense...
[color=blue]
> Richard.[/color]
Again thanks for spending your time, i will take a closer look on this
article later (at the moment i am quite busy).
Marc