Hi reader,
recently i found out you can set typs of variables and make your own types aswell.
I typed over another ones code but just the part i want to understand.
The script
export type Person = {
__index: Person,
Name: string,
Age: number,
Object: Instance,
new: () -> (Person),
setName: (self: Person) -> ()
}
local personClass: Person = {} :: Person
personClass.__index = personClass
function personClass.new()
local self: Person = {} :: Person
self.Name = "Person"
self.Age = 18
self.Object = Instance.new("Model")
return setmetatable(self :: any, personClass)
end
function personClass:setName (name)
self.Name = name
return self
end
local person1 = personClass.new()
local person2 = personClass.new()
warn(person1, person2)
person1:setName("Another name")
warn(person1, person2)
it all works and does what you expect but i have some questions like:
What is the first and second () for?
setName: (self: Person) -> ()
What does ::
do?
And what are other possiblities by coding like this?