• 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: *Very* strange script / global variable behavior
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: *Very* strange script / global variable behavior


  • Subject: Re: *Very* strange script / global variable behavior
  • From: Michael Johnston <email@hidden>
  • Date: Wed, 2 Mar 2005 14:17:21 +0100

This is not a bug, it's a feature! It's a closure! sort of. Ruby and Python also have closures, and Javascript used to. I miss closures in Javascript. I was sad when they omitted them from the ecmascript spec.

The purpose of a closure is to capture the state of variables at the time the block is instantiated. "set x to Outer" is instantiating the block Inner. What does seem to be a bug, or a limitation at least, is that I can't seem to figure out how to re-map the "closure" to a different set of values for the local properties at different times...

Closures make implementing systems of callbacks much easier.

Michael Johnston
Planetactive

On 27-Feb-05, at 11:43 PM, Neil Faiman wrote:

Yet another, still simpler, variation on this puzzle:

	property theState : 0

	script Inner
		on showTheState()
			display dialog "State " & theState
		end showTheState
	end script

	script Outer
		Inner
	end script

	set x to Outer

	set theState to 1
	tell Inner to showTheState()
	set theState to 2
	tell Inner to showTheState()

As before, running this program will display "State 0" twice. Either changing the "property" declaration to a "global" declaration, or commenting out the "set x to Outer" statement, will cause it to display "State 1", "State 2".

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden


This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Applescript-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Prev by Date: Re: Why does this filter expression not work? Anyone have an idea?
  • Next by Date: Re: Auto Mount Server with Apple Script (Beginner Here)
  • Previous by thread: Re: *Very* strange script / global variable behavior
  • Next by thread: Re: *Very* strange script / global variable behavior
  • Index(es):
    • Date
    • Thread