Skip to main content

$THIS (ObjectScript)

Contains the current class context.

Synopsis

$THIS

Description

$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 ..property = 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. For information on OREFs, see OREF Basics.

See Also

FeedbackOpens in a new tab