Class Fonctions
Class Fonctions
What is the purpose of the _ and __ signs used in at the beginning of functions in classes? I really have a hard time understanding.
Re: Class Fonctions
They have no special meaning to the program. A few reserved method names start with __, these methods have special meaning but not due the __. See meta functions. Also see _newenum .
Sometimes script authors prefix underscores to indicate that a method is intended to be private, it is only a naming convention and has no real impact.
Cheers.
Sometimes script authors prefix underscores to indicate that a method is intended to be private, it is only a naming convention and has no real impact.
Cheers.
Re: Class Fonctions
Thank you so much. That was certainly enough explanation for me.
and : Can you explain the statements? I have difficulty understanding the guide.
Code: Select all
this
Code: Select all
base
Re: Class Fonctions
When you define a method, autohotkey will add one extra parameter to it, called this, example, if you write,
then, when the script is loaded, AHK will turn it into
Then, when you call the method, autohotkey will automatically pass the invoking object to the this parameter. For example, if you do,
then AHK will pass myObj to myMethod as the first parameter, before the parameters you passed yourself, i.e., 1,2 in this example, so inside myMethod the this parameter is now equal to myObj. But if you call the method with myObj2, this is equal to that object instead.
The keyword base is typically used to call an overridden method. Example,
Cheers.
Code: Select all
class myClass {
myMethod(Param1, Param2) {
}
}
Code: Select all
class myClass {
myMethod(this, Param1, Param2) {
}
}
Code: Select all
myObj := new myClass
myObj.myMethod(1,2)
The keyword base is typically used to call an overridden method. Example,
Code: Select all
c := new A
c.myMethod() ; calls (1)
class A extends B {
myMethod() { ; (1)
base.myMethod() ; calls (2)
}
}
class B {
myMethod() { ; (2)
}
}
Re: Class Fonctions
_NewEnum is a single underscore
Re: Class Fonctions
Thank you so much. I still don't understand.Helgef wrote: ↑12 Jul 2019, 01:48When you define a method, autohotkey will add one extra parameter to it, called this, example, if you write,then, when the script is loaded, AHK will turn it intoCode: Select all
class myClass { myMethod(Param1, Param2) { } }
Then, when you call the method, autohotkey will automatically pass the invoking object to the this parameter. For example, if you do,Code: Select all
class myClass { myMethod(this, Param1, Param2) { } }
then AHK will pass myObj to myMethod as the first parameter, before the parameters you passed yourself, i.e., 1,2 in this example, so inside myMethod the this parameter is now equal to myObj. But if you call the method with myObj2, this is equal to that object instead.Code: Select all
myObj := new myClass myObj.myMethod(1,2)
The keyword base is typically used to call an overridden method. Example,Cheers.Code: Select all
c := new A c.myMethod() ; calls (1) class A extends B { myMethod() { ; (1) base.myMethod() ; calls (2) } } class B { myMethod() { ; (2) } }
Am I not enough to learn object orientation? I don't know where the problem is. But maybe a more obvious example would be my remedy. Even if I don't want to bother you.
Last edited by hasantr on 08 Jan 2020, 14:49, edited 1 time in total.
Re: Class Fonctions
Perhaps you will have more luck with one of the tutorials. I don't think I can help you unless you make a more specific question, but I think you should start a new thread for that anyways.
@swagfag, the op specifically asked about single and double underscore prefixed method names, hence why I mentioned _newenum .
Cheers.
@swagfag, the op specifically asked about single and double underscore prefixed method names, hence why I mentioned _newenum .
Cheers.
Re: Class Fonctions
Thank. Somehow I have to do this myself. Thank you for trying.Helgef wrote: ↑19 Jul 2019, 04:02Perhaps you will have more luck with one of the tutorials. I don't think I can help you unless you make a more specific question, but I think you should start a new thread for that anyways.
@swagfag, the op specifically asked about single and double underscore prefixed method names, hence why I mentioned _newenum .
Cheers.
I'm constantly reviewing case studies, Autohotkey will take some time, but don't give up.
Re: Class Fonctions
Thanks. Now I can understand that.Helgef wrote: ↑12 Jul 2019, 01:48When you define a method, autohotkey will add one extra parameter to it, called this, example, if you write,then, when the script is loaded, AHK will turn it intoCode: Select all
class myClass { myMethod(Param1, Param2) { } }
Then, when you call the method, autohotkey will automatically pass the invoking object to the this parameter. For example, if you do,Code: Select all
class myClass { myMethod(this, Param1, Param2) { } }
then AHK will pass myObj to myMethod as the first parameter, before the parameters you passed yourself, i.e., 1,2 in this example, so inside myMethod the this parameter is now equal to myObj. But if you call the method with myObj2, this is equal to that object instead.Code: Select all
myObj := new myClass myObj.myMethod(1,2)
The keyword base is typically used to call an overridden method. Example,Cheers.Code: Select all
c := new A c.myMethod() ; calls (1) class A extends B { myMethod() { ; (1) base.myMethod() ; calls (2) } } class B { myMethod() { ; (2) } }
Who is online
Users browsing this forum: Descolada, inseption86, jaka1, mikeyww and 442 guests