Re: Scope of globals, parents and children etc.
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