• 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: Non Compulsory Parameters & a Null Constant ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Non Compulsory Parameters & a Null Constant ?


  • Subject: Re: Non Compulsory Parameters & a Null Constant ?
  • From: has <email@hidden>
  • Date: Wed, 12 Feb 2003 18:05:28 +0000

Adam Hinshaw wrote:

is there a way to specify parameters in a handler that are not compulsory in
a call to that handler.

Handler parameters are non-optional (annoying, but that's how it is). You can work around this when you have to:

on doSomething(paramRec)
set {foo:foo, bar:bar} to paramRec & {foo:0, bar:false}
log foo
log bar
end

doSomething({})
doSomething({foo:4})
doSomething({foo:19, bar:true})

It's kinda ugly, but may be the lesser evil when writing handlers that must have this level of flexibility and self-sufficiency (e.g. reusable libraries). Rest of the time, it's simpler just to be explicit:

on doSomething(foo, bar)
...
end

If it'll make your code easier to read/maintain, you can always define your default values up front as 'constants':

-- constants/default values
property dcFoo : 0
property dcBar : false

...

doSomething(dcFoo, dcBar)
doSomething(dcFoo, true)
--
http://www.barple.pwp.blueyonder.co.uk -- The Little Page of AppleScripts
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Non Compulsory Parameters & a Null Constant ?
      • From: Adam Hinshaw <email@hidden>
    • Re: Non Compulsory Parameters & a Null Constant ?
      • From: Paul Skinner <email@hidden>
  • Prev by Date: Arrangement of display 1 & 2
  • Next by Date: Saving a temp file?
  • Previous by thread: Re: Non Compulsory Parameters & a Null Constant ?
  • Next by thread: Re: Non Compulsory Parameters & a Null Constant ?
  • Index(es):
    • Date
    • Thread