• 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: Scope of globals, parents and children etc.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scope of globals, parents and children etc.


  • Subject: Re: Scope of globals, parents and children etc.
  • From: Brennan Young <email@hidden>
  • Date: Mon, 21 May 2001 12:57:00 +0200
  • Organization: Magic Lantern

Oops! I just realised my demonstration of instances is a bit screwy because I
had to change the property 'name' to the property 'moniker' to get it to compile
on this machine, only I didn't change every occurrence:

on run
set bill to x()
bill's init("William Gates")

set Maggie to x() -- a different instance!
Maggie's init("Margaret Thatcher")

bill's greeting()
Maggie's greeting()
end run

-- a constructor function contains a script object
-- and returns a new instance of the script
on x()

script z
property moniker : ""
property age : 0
on init(n)
set moniker to n
set age to (random number from 1 to 99)
end init

on greeting()
set greeting to "Hello, my name is " & moniker & " and my age is " & age
display dialog greeting
end greeting

end script

return z -- this is the magic part. It returns a unique copy of z!

end x

--
_____________

Brennan


  • Prev by Date: Re: Scope of globals, parents and children, "load script" and all that
  • Next by Date: Re: SECOND POST: Changing Access Privs
  • Previous by thread: [Q]How to set Microphone Gain with a script
  • Next by thread: Re: SECOND POST: Changing Access Privs
  • Index(es):
    • Date
    • Thread