Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Well, I'm Confused...



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.




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.