Use whatever approach you want, but value.methodname will not return the method/function if there is also a getter.
Code: Select all
class value {
static methodname => 'nope!'
static methodname() => 'return value'
}
MsgBox value.methodname ; nope!
MsgBox value.GetMethod('methodname').Name ; value.methodname
MsgBox value.GetMethod('methodname')(value) ; return value
MsgBox (value.methodname)(value) ; Error (can't call string)
The method definition below creates a property of the same type as target.DefineProp('Method', {call: funcObj}). By default, target.Method returns funcObj and attempting to assign to target.Method throws an error. These defaults can be overridden by defining a property or calling DefineProp.
Source: Objects - Definition & Usage | AutoHotkey v2
If any one of the accessor functions is omitted, behavior is inherited from a base object.Source: Object - Methods & Properties | AutoHotkey v2
- An inherited value property is equivalent to a set of accessor functions which return or call the value, or store a new value in this. Note that a new value would overwrite any dynamic property in this itself, and override any inherited accessor functions.
- If no Set or value is defined or inherited, attempting to set the property will throw an exception.
- If no Call is defined or inherited, Get may be called to retrieve a function object, which is then called.
- If no Get is defined or inherited but there is a Call accessor function, the function itself becomes the property's value (read-only).
Given the following, I might remove GetMethod:
- GetMethod can't handle all ways of defining a method.
- value.methodname is more convenient.
- value.methodname works in the common cases.
- value.methodname is more consistent with functionname and value.methodname().