• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Handlers in a variable
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Handlers in a variable


  • Subject: Re: Handlers in a variable
  • From: Bernard Moreau <email@hidden>
  • Date: Wed, 20 Jan 2016 21:28:12 +0100

Hi Chris,

Thanks for sharing this interesting stuff.
I'm far of being an AS specialist.
Please help me to understand why we need the
      set aValue to "3"
it seems to work too without this statement ?
Best regards.

Bernard.

2016-01-20 19:34 GMT+01:00 Christopher Stone <email@hidden>:
On Jan 19, 2016, at 19:32, Stockly, Ed <email@hidden> wrote:
The version above works only if someHandler is a property. If you note out that line it fails.
______________________________________________________________________

It works fine if you declare someHandler as a global variable.

I think this demonstrates scope more clearly than using a Property (provided you don't need it to be a Property).

--
Take Care,
Chris

------------------------------------------------------------
global someHandler
------------------------------------------------------------

DoFirstHander()
someHandler(4)
call(double, 4)
DoMyHandler()

------------------------------------------------------------
on double(aNumber)
  return aNumber * 2
end double
------------------------------------------------------------
on call(someHandler, aValue)
  someHandler(aValue)
end call
------------------------------------------------------------
on DoMyHandler()
  someHandler(4)
  call(double, 4)
end DoMyHandler
------------------------------------------------------------
on DoFirstHander()
  set aValue to "3"
  set someHandler to double
  someHandler(4) -- Fails here if someHandler is not global.
end DoFirstHander
------------------------------------------------------------


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Handlers in a variable
      • From: "Stockly, Ed" <email@hidden>
References: 
 >Handlers in a variable (From: "Mark J. Reed" <email@hidden>)
 >Re: Handlers in a variable (From: Chris Page <email@hidden>)
 >Re: Handlers in a variable (From: "Stockly, Ed" <email@hidden>)
 >Re: Handlers in a variable (From: Chris Page <email@hidden>)
 >Re: Handlers in a variable (From: "Stockly, Ed" <email@hidden>)
 >Re: Handlers in a variable (From: Christopher Stone <email@hidden>)

  • Prev by Date: Odd Speed Issue with choose folder
  • Next by Date: Re: Handlers in a variable
  • Previous by thread: Re: Handlers in a variable
  • Next by thread: Re: Handlers in a variable
  • Index(es):
    • Date
    • Thread