• 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: "Stockly, Ed" <email@hidden>
  • Date: Wed, 20 Jan 2016 01:32:28 +0000
  • Thread-topic: Handlers in a variable


property someHandler : ""


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 a property

end DoFirstHander

on run

set someHandler to ""

DoFirstHander()

someHandler(4)

call(double, 4)

DoMyHandler()

end run

  
>>>Most of that is the same as the OP's code.

Well, yes but there are important modifications. I think the OP's script simply had a mislabeled variable, which caused the failure.

 >>>What are you trying to convey?

The version above works only if someHandler is a property. If you note out that line it fails.

So even though handlers are global in scope, for some reason you can't set a local variable to a handler, but you can set a global variable or a property to a handler.

(In your previous example, the variable wasn't a property, but it was global, not local.)

ES


 _______________________________________________
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: Christopher Stone <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>)

  • Prev by Date: Re: Handlers in a variable
  • 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