• 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: Inheritance dilemma
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Inheritance dilemma


  • Subject: Re: Inheritance dilemma
  • From: Paul Berkowitz <email@hidden>
  • Date: Mon, 21 Apr 2003 10:17:32 -0700

On 4/21/03 9:35 AM, "David Graham" <email@hidden> wrote:

> (Given a script library 'libTest' with the following property)
>
> property foo : "bar"
>
>
> When I execute the following, it functions as I would expect:
>
> -- EXAMPLE 1
>
> property parent : load script alias "Dave's
> HD:Users:dgraham:Desktop:libTest"
>
> get foo
>
> --> "bar"
>
>
>
>
> So if the parent script's properties are treated as it's own, why don't
> the handlers inherit them as well?
>
> -- EXAMPLE 2
>
> property parent : load script alias "Dave's
> HD:Users:dgraham:Desktop:libTest"
>
> TestInheritance()
>
> to TestInheritance()
>
> get foo
>
> end TestInheritance
>
> --> Error "The variable foo is not defined."

A good question. But when in doubt, try 'my':


property parent : load script alias "OS X HD:Users:berkowit:Desktop:testlib"

TestInheritance()
-->"bar"

to TestInheritance()

get my foo

end TestInheritance


Your handler was implicitly declaring a new variable foo with local scope,
which is the default in handlers when no global is explicitly declared. It
is a bit odd that that doesn't take over foo as its own property. This also
works:


property parent : load script alias "OS X HD:Users:berkowit:Desktop:testlib"

TestInheritance()
--> "bar"

to TestInheritance()

global foo

get foo

end TestInheritance


That way you're declaring the top-level foo as global to this handler.
Finally, this will work too:


property parent : load script alias "OS X HD:Users:berkowit:Desktop:testlib"
global foo

TestInheritance()
--> "bar"

to TestInheritance()

get foo

end TestInheritance




--
Paul Berkowitz
_______________________________________________
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.

  • Follow-Ups:
    • Re: Inheritance dilemma
      • From: David Graham <email@hidden>
References: 
 >Inheritance dilemma (From: David Graham <email@hidden>)

  • Prev by Date: Re: Read file bug?
  • Next by Date: Safari and POST data
  • Previous by thread: Inheritance dilemma
  • Next by thread: Re: Inheritance dilemma
  • Index(es):
    • Date
    • Thread