Topic: APLX Help : Help on APL language : System Functions & Variables : ⎕THIS Reference to current object
[ Previous | Next | Contents | Index | APL Home ]

www.microapl.co.uk

⎕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 | APL Home ]