can I call a handler "by reference"?

I can grab a reference to a handler:

set my_reference to my do_stuff 
-- result: «handler do_stuff»

But is it possible to call that handler? This is a normal operation in most programming languages, including many scripting languages, but I’m uncertain how to go about it in Applescript.

My motive: I’d love to have a list of handlers I could call according to certain generic criteria.

TIA.

Answering my own question: It’s even easier than I thought!
Simply do:


set handler_reference to my do_stuff 
handler_reference()

to invoke do_stuff!

Hi,

I like it when people do experimenting on there own and find out stuff! :slight_smile:

You could place your handlers in a list and reference them by index. For example:


set h_list to {a, b, c}
set h to item 2 of h_list
h()
--
on a()
	say "a"
end a
--
on b()
	say "b"
end b
--
on c()
	say "c"
end c

gl,

Just to note that all the variables used have to be globals or properties, so you have to declare them as such if you use the method inside a handler.