Retrieves the implementation function of a method.
Method := GetMethod(Value , Name, ParamCount)
Type: Any
Any value, of any type except ComObject.
Type: String
If omitted, validation is performed on Value itself and Value is returned if successful. Otherwise, specify the name of the method to retrieve.
If omitted (or if the parameter count was not verified), a basic check is performed for a Call method to verify that the object is most likely callable.
Otherwise, specify the number of parameters that would be passed to the method or function. If specified, the method's MinParams, MaxParams and IsVariadic properties may be queried to verify that it can accept this number of parameters. If those properties are not present, the parameter count is not verified.
This count should not include the implicit this
parameter.
Type: Function Object
This function returns the function object which contains the implementation of the method, or Value itself if Name was omitted.
If the method is not found or cannot be retrieved without invoking a property getter, a MethodError is thrown.
If validation is attempted, exceptions may be thrown as a result of querying the method's properties. A ValueError or MethodError is thrown if validation fails.
Methods may be defined through one of the following:
{Call: fn}
to DefineProp, where fn implements the method.When calling the function object, it is necessary to supply a value for the normally-hidden this parameter. For example, Method(Value, Parameters*)
.
Although the standard implementation of GetMethod has limitations as described above, if Value.GetMethod(Name)
is used instead of GetMethod(Value, Name)
, the object Value can define its own implementation of GetMethod.
GetMethod(Value, "Call", N)
is not the same as GetMethod(Value,, N)
, as the Call method takes the function object itself as a parameter, and its usage may otherwise differ from that of Value. For instance, Func.Prototype.Call
is a single method which applies to all built-in and user-defined functions, and as such must accept any number of parameters.
Objects, HasMethod, HasBase, HasProp
Retrieves and reports information about the GetMethod method.
method := GetMethod({}, "GetMethod") ; It's also a method. MsgBox method.MaxParams ; Takes 2 parameters, including 'this'. MsgBox method = GetMethod ; Actually the same object in this case.