Understanding "Bind Method" Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
murataygun
Posts: 104
Joined: 07 Aug 2015, 15:53

Understanding "Bind Method"

30 Jul 2021, 04:36

My script got messy and I'm rewiriting my whole script from the beginning. On the way i'm following OOP principles. I'm reading docs. Figuring out what is the best way. So i could'nt really understand how bind method works.

I've used somethin like this. But I have no idea how it works.

Can you guide me with a couple of sentences?

Code: Select all

IF (TELEMETRI) {
	;RutinCheck True/False
	rutinCheckFuncReferance := Func("Telemetri").Bind("rutinCheck")
	SetTimer, % rutinCheckFuncReferance, %TELEMETRI_INTERVAL%
}
User avatar
Chunjee
Posts: 1500
Joined: 18 Apr 2014, 19:05
Contact:

Re: Understanding "Bind Method"  Topic is solved

30 Jul 2021, 05:04

I think of bind as glue. You glue a parameter to a function and can call it without the parameter later.

Code: Select all

boundFunc := Func("StrLen").bind("a parameter")
msgbox, % boundFunc.call()
; => 11

; same as
msgbox, % StrLen("a parameter")
; => 11

Now StrLen only takes one parameter; but bind can glue one or more parameters. So maybe you run into a situation where you know the first parameter is always the same, but the second parameter may be adjustable. you can bind that first parameter and supply the second as needed.

Code: Select all

boundFunc := Func("InStr").bind("Haystack")
msgbox, % boundFunc.call("0000") ; same as InStr("Haystack", "0000")
; => 0
msgbox, % boundFunc.call("Hay") ; same as InStr("Haystack", "Hay")
; => 1

In the code you posted; a timer is stared and calls the function with its parameter glues on. This is probably useful for scope since it doesn't have to have keep access to that parameter at the timer scope.
murataygun
Posts: 104
Joined: 07 Aug 2015, 15:53

Re: Understanding "Bind Method"

30 Jul 2021, 05:22

Very clear. Thank you. :thumbup:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], dra3th, Mateusz53, mstrauss2021, Rohwedder, Spawnova and 283 guests