Home / ObjectScript Reference / ObjectScript Special Variables / $THIS

ObjectScript Reference
Previous section           Next section
InterSystems: The power behind what matters   

Contains the current class context.
$THIS contains the current class context. The class context for an instance method is the current object reference (OREF). The class context for a class method is the current classname as a string value. For example, if you issue the command DO ..method() or SET = value from within a class method, the .. context is resolved using the current value of $THIS. When making a reference within an object instance, the relative dot syntax (..) is preferred.
$THIS is commonly used when you are within an object instance and you call a function that is on another object. In this circumstance, you can use $THIS to pass the current class context to that function, so that it can return a value to your current object instance.
When $THIS does not contain a valid object reference, InterSystems IRIS returns a <NO CURRENT OBJECT> error.
$THIS can be used in the contexts such as the following:
SET x = ##class(otherclassname).method($THIS)

DO ##class(superclass)$THIS.method(args)
This special variable cannot be set to a value using the SET command. Attempting to do so results in a <FUNCTION> error.
For further details, refer to “$this Syntax” in Object-specific ObjectScript Features chapter of Defining and Using Classes. For information on OREFs, see OREF Basics in Defining and Using Classes.
See Also

Previous section           Next section
View this book as PDF   |  Download all PDFs
Copyright © 1997-2019 InterSystems Corporation, Cambridge, MA
Content Date/Time: 2019-04-19 08:40:24