stretch65 wrote:I've changed the code to the following (with no error messages):
You will get an error message when you attempt to invoke the menu item's callback, because you have not defined the required parameters. If you do, as shown above,
Code: Select all
static doStuff(ItemName, ItemPos, Menu) {
msgbox "Inside 'doStuff()'"
}
You'll still get an error message because ahk passes three parameters, but the method has a fourth, hidden parameter, that is
this. You'll have to fill it in yourself as it is only implicitly passed when using the method call syntax, i.e.,
o.m(). So use
bind() as shown by swagfag. Some examples to show,
Code: Select all
class c {
static g(){
msgbox this == c
? 'this == c is true'
: 'this is the string:`t"' . this . '"'
}
}
c.g() ; "normal call"
g := c.getmethod('g')
%g%('abc') ; call func reference, when you pass a reference to any built in function such as settimer or onmessage,
; this is how it will be called and behave.
g := g.bind(c)
%g%() ; call a boundfunc, behaves as normal call if bound "correctly".
; Pass boundfuncs to built in functions to make the callback behave like normal calls.
Also see
Function objects.
Cheers.