Re: Handlers in list
Re: Handlers in list
- Subject: Re: Handlers in list
- From: Brennan Young <email@hidden>
- Date: Mon, 23 Apr 2001 11:38:10 +0200
- Organization: Magic Lantern
"Neal A. Crocker" <email@hidden> wrote
>
Instead, do this:
I've been trying to understand this. It looks really useful but I don't
quite get it. I've boiled your example down to this
on dummyHandler()
display dialog "this never happens"
end dummyHandler
set myhandlers to {testA, testB, testC}
set r to random number from 1 to 2
set dummyHandler to item r of myhandlers -- ***
dummyHandler()
on testA()
display dialog "testA"
dummyHandler
end testA
on testB()
display dialog "testB"
dummyHandler
end testB
on testC()
display dialog "testC"
dummyHandler
end testC
So the bit I'm a bit confused about is the line marked ***.
Where is all this documented? I can't find anything about it in
Applescript Language Guide
We're assigning the name of a handler to a variable whose name is the
same as another handler.
When we call that handler subsequently, the assigned handler is used instead.
I'm getting <<handler testA>> (etc.) as the result from these. So, a
handler is an object too?
Lots to explore here. What's interesting is that the dummy handler does
not need any parameters, even if it is 'overridden' by one which does.
-- setup dummies...
on doThis()
end doThis
on doThat()
end doThat
-- assign a bona fide handler to one of the dummies
set doThat to testB
-- call it, with one of the other handlers as a paramter
doThat(testA)
on testA()
display dialog "testA"
end testA
on testB(which)
display dialog "testB"
set doThis to which
doThis()
end testB
--
_____________
Brennan