• 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: Well, I'm Confused...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Well, I'm Confused...


  • Subject: Re: Well, I'm Confused...
  • From: Axel Luttgens <email@hidden>
  • Date: Wed, 28 Apr 2004 00:03:14 +0200

email@hidden wrote:

I thought both values should be "Child Value", since the Child's property overrides the Parent's property. Silly me.

What am I missing?

script theParent
property zzz : "Parent Value"
on send()
return zzz
end send
end script

on makechild()
script theChild
property parent : theParent
property zzz : "Child Value"
return (theChild)
end script
end makechild

set theChild to makechild()
{theChild's zzz, theChild's send()}

--> {"Child Value", "Parent Value"}


As Paul already noticed, the usage of makechild() as a constructor function is more sensible with the return statement outside of the "script theChild" block; so:

-- Code1

script theParent
property zzz : "Parent Value"
on send()
return zzz
end send
end script

on makechild()
script theChild
property parent : theParent
property zzz : "Child Value"
end script
return theChild
end makechild

set theChild to makechild()
{theChild's zzz, theChild's send(), theParent's send()}
--> {"Child Value", "Parent Value", "Parent Value"}

But now notice the seemingly innocent "my" keyword:

-- Code2

script theParent
property zzz : "Parent Value"
on send()
return my zzz
end send
end script

on makechild()
script theChild
property parent : theParent
property zzz : "Child Value"
end script
return theChild
end makechild

set theChild to makechild()
{theChild's zzz, theChild's send(), theParent's send()}
--> {"Child Value", "Child Value", "Parent Value"}

With Code1, only lexical scoping gets involved: handler "on send" recognizes zzz as not being a local variable because identifier zzz appears before as a property name.
With Code2, you explicitely add the notion of inheritance; this is no lexical matter anymore.

Not sure I managed to be be clear,
But nevertheless HTH ;-)
Axel
_______________________________________________
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.


  • Prev by Date: Re: Backing up only new files
  • Next by Date: Re: Using Applescript to save a text file?
  • Previous by thread: Re: Well, I'm Confused...
  • Next by thread: Using Applescript to save a text file?
  • Index(es):
    • Date
    • Thread