| re: OOP: dynamic arguments in callback functions?
Tyler wrote:[color=blue]
> Hi all,
>
> I am using some components from a JS library (scriptalicious), where
> callback functions are arguments to the constructors of the components
> like so:
>
> someClass x (name)
> {
> this.name = name;
> this.slider = new
> Control.Slider(this.name+'slide',this.name+'track' ,{
> onSlide:function(v){foo()},
> onChange:function(v){bar(v)}
> );
> }
> Since I would like to dynamicaly create these components at runtime, I
> would like the engine (the browser) to evaluate the value of a member
> variable (this.name) and to pass this to the callback of the event,
> like
> .... onChange:function(v){bar(this.name)} ...
> Is this possible by some escaping mechanism or so? (and am I making
> myself clear enough?)?
>[/color]
If you bind the information you will to provide to the callcack function
to the element with the callback, you can access it through the event.
Something like
element.info = {name:this.name};
element.onChange = callback;
function callback( event )
{
// x-browser code to get the event.
var info = event.target.info;
};
--
Ian Collins. |