Re: Preview of changes: scope, function and variable references
Posted: 07 Apr 2021, 03:12
@QiuDao The proper way to use quote tags is to include what the other person said inside the tags, and write your own question outside the tags. Your use of the quote tags is very confusing, and your phrasing does not help (I presume they are your words, as they are not mine).
Use whatever approach you want, but value.methodname will not return the method/function if there is also a getter.
Given the following, I might remove GetMethod:
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().