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

Re: Script Objects


  • Subject: Re: Script Objects
  • From: Luther Fuller <email@hidden>
  • Date: Tue, 19 Jan 2010 08:30:31 -0600

On Jan 18, 2010, at 10:50 PM, Chris Page wrote:
script Person
property FullName : "Anonymous"
property Title : "Unknown"

on SayHello()
set message to "Hello, my name is " & FullName & ", " & Title & "."
log message
say message
end SayHello
end script

copy Person to Elmer
set Elmer's FullName to "Elmer J. Fudd"
set Elmer's Title to "Millionaire"

copy Person to Shake
set Shake's FullName to "Shake Zula"
set Shake's Title to "Mike Rula"

tell Shake to SayHello()
tell Person to SayHello()
tell Elmer to SayHello()

Let's call this code-1 and shorten it to this ...

script Person
property FullName : "Anonymous"
property Title : "Unknown"


on SayHello()
set message to "Hello, my name is " & FullName & ", " & Title & "."
-- log message
say message
end SayHello
end script
copy Person to Elmer
set Elmer's FullName to "Elmer J. Fudd"
set Elmer's Title to "Millionaire"
tell Elmer to SayHello()

Now, consider the script ...

-- this space reserved for some code
-----------------------
Elmer's FullName

What goes into the reserved space? If you put code-1 into the reserved space, then "Elmer J. Fudd" is written to the console. But, I could have put this code-2 into the reserved space ...

set Elmer to {Title:"Millionaire", FullName:"Elmer J. Fudd"}
on SayHello(Person)
set message to "Hello, my name is " & (FullName of Person) & ", " & (Title of Person) & "."
say message
end SayHello
tell me to SayHello(Elmer)

and gotten the same result. The line 'Elmer's FullName' can't tell the difference between a record and a script object. But, a script object can contain handlers associated with its data. Code-2 is a lot shorter than code-1 and I would prefer it. But ...

Is there any advantage to associating the data and the handlers for the data by using a script object?

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Script Objects
      • From: "Mark J. Reed" <email@hidden>
References: 
 >Script Objects (From: Luther Fuller <email@hidden>)
 >Re: Script Objects (From: Chris Page <email@hidden>)

  • Prev by Date: Re: Applescript Trivia: Black & White Pinwheel?
  • Next by Date: Re: Script Objects
  • Previous by thread: Re: Script Objects
  • Next by thread: Re: Script Objects
  • Index(es):
    • Date
    • Thread