← Back to Docs
this Keyword
this accesses variables declared at the class scope from anywhere inside the class.
Syntax
this.variableNameWhy use this?
When you are inside a function, local parameters can shadow class-level variables. this lets you explicitly reach the class scope.
Example
class App {
let name = "VDX";
let version = 1;
print(this.name); // VDX
print(this.version); // 1
}Inside functions
class App {
let lang = "VDX";
fn showLang() {
// 'this.lang' reaches the class-level variable
print("Language:", this.lang);
}
showLang(); // Language: VDX
}In conditions
class App {
let mode = "debug";
if (this.mode == "debug") {
print("Debug mode is on");
}
}Rules
thismust be followed by.and a field name- Using
thisalone is a syntax error - Accessing an undefined field throws a runtime error