local a = "hello"
print(a.upper("Sup")) -- Prints ("SUP")
My question is, how does this work, it puts the "upper" function to the variable "a" but how? and why does this work?
local a = "hello"
print(a.upper("Sup")) -- Prints ("SUP")
My question is, how does this work, it puts the "upper" function to the variable "a" but how? and why does this work?
a is an Instance of the String base-class. Thus, it will inherit the functions belonging to it (indexable by the dot operator). If you wish to call the methods of the String Object, you must use a colon prefix.
("").upper("Hello world!") --> HELLO WORLD
--// Interpreted as:
string.upper("Hello world!") --> HELLO WORLD
####If you wish to understand more about this underlying model, research OOP (Object-oriented Programming).
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
Thank you this helped a lot