## ŚTHIS Reference to current object

The niladic system function ŚTHIS returns a reference to the user-defined object whose method is currently being executed. If no method is currently executing, it returns a Null object.

          ’MyClass{
    {MyClass}:
          ’RunMe
    [1]   'I am an instance of ',ŚTHIS.ŚCLASSNAME
    [2]   'In fact, I am an instance of ',ŚCLASSNAME
    [3]   ŚCLASS ŚTHIS
    [4]   ’
    {MyClass}:
          }

          M„ŚNEW 'MyClass'
          M.RunMe
    I am an instance of MyClass
    In fact, I am an instance of MyClass
    {MyClass}
          ŚTHIS
    [NULL OBJECT]

When a method is running, ŚTHIS is implicit when accessing class members or system methods. That is why ŚTHIS.ŚCLASSNAME and ŚCLASSNAME give the same result in the above example. For this reason, you normally do not need to use ŚTHIS except when you want to pass a reference for the current object to another object or to a global function.

Topic: APLX Help : Help on APL language : System Functions & Variables : ŚTHIS Reference to current object

[ Previous | Next | Contents | Index ]