• 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
script objects & multiple constructors
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

script objects & multiple constructors


  • Subject: script objects & multiple constructors
  • From: vectormation <email@hidden>
  • Date: Wed, 3 Oct 2001 17:05:46 -0400

O learned scripting experts...

How do I achieve the equivalent of overridden constructors with
AppleScript script objects?

My data structure may need to be initialized with various subsets of the
total properties, and in c++ or java you just create multiple
constructors, with each one defining the various parameter subsets...

example
===========================================================================

on run
set myDemo to newDemo({name:"Bozo", age:31, job:"comedian",
usesMac:true})
display dialog (toString() of myDemo)
end run

on newDemo(myRecord)
script demo
property demoName : "Foo Bar"
property demoAge : 0
property demoJob : "unemployed"
property demoGender : "eunuch"
property demoMacUser : false

on init(aRecord)
set demoName to name of aRecord
set demoAge to age of aRecord
set demoJob to job of aRecord
-- set demoGender to sex of aRecord
-- runtime errors if not provided
set demoMacUser to usesMac of aRecord
end init

on toString()
set rezStr to "Name :" & demoName & return
set rezStr to rezStr & "Age :" & demoAge & return
set rezStr to rezStr & "Job :" & demoJob & return
set rezStr to rezStr & "Sex :" & demoGender & return
set rezStr to rezStr & "Mac? :" & demoMacUser & return

return rezStr
end toString
end script

tell demo to init(myRecord)

return demo
end newDemo
===========================================================================


As AS will not let you define handlers with the same name, but differing
parameter lists... how can I get around it? I've tried using a record,
but then how do I avoid runtime errors when I try to initialize a value
to one not in the given record? Surely this has come up before, as I'm
not that sophisticated a scripter (yet)


~Phi


  • Prev by Date: Re: Getting info out of Mail messages
  • Next by Date: Re: Display PICT in DD?
  • Previous by thread: Re: Applescript Studio Announced Today
  • Next by thread: XC: Getting URL infomation from browser
  • Index(es):
    • Date
    • Thread