method. Getting object's method   [3.4.2]

^reflection:method[object;method name]
^reflection:method[class;method name]

Returns method of object or class. The method could be used in user-defined classes where the field has priority over the method with the same name.

^reflection:method[метод]   [3.4.5]
^reflection:method[метод;объект]   [3.4.5]

Binds a method to the object or class that called it, or to the object or class passed in the second parameter. In Parser all methods
are bound to the execution context (self) and this way you can change this binding.

Example

@main[]
$a[^A::create[]]

^a.m[] - m method can't be used directly as field m has a priority over it
thus using ^reflection:method[] to get m method

$method[^reflection:method[$a;m]]
^method[]

$b[^B::create[]]

We substitute self to call the method m in the context of another object, we store result in object b
$b.m[^reflection:method[$method;$b]]

# now object b has method m
^b.m[]

@CLASS
A

@create[]
$name[object of class A]
$m[object field]

@m[]
method of class A, called on $name

@CLASS
B

@create[]
$name[object of class B]

Returns:

method of class A, called on object of class A
method of class A, called on object of class B




Copyright © 1997–2021 Art. Lebedev Studio | http://www.artlebedev.com Last updated: 25.04.2017