Friday, July 28, 2017

#1 2005-10-13 02:47:43 pm

julifos
Administrator
From:: Malasaña, Madrid
Registered: 2002-11-20
Posts: 2014

What are "constructors"?

Constructors are not part of the AppleScript terminology, but user-defined functions. Basically, they are handlers concibed to create objects from scratch, initializing their values with some data. Making use of other words: templates for applescript items (handlers, properties, etc.).

Applescript:

--> this is a template (the constructor)
to createCharacter(x, y, z)
   script blank
       property userName : x
       property userAge : y
       to sayHisName()
           say "My name is " & userName & " and I'm " & userAge & " years old"
       end sayHisName
       script dog
           property dogName : z
       end script
   end script
end createCharacter

--> we use the template to create two characters, called "John" and "Harry"
set John to createCharacter("John", 13, "Bo Derek")
set Harry to createCharacter("Harry", 54, "Tyler Hamilton")

--> we use the handler "sayHisName" of the new object called "John"
tell John to sayHisName()

--> and we are interested in the property "dogName" of Harry's dog
say dogName of dog of Harry

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)