Code: Select all
tes:=new test()
Msgbox % tes.abc
class test{
__new()
{
this.abc:=1
this:=new test2()
this.abc:=0
}
}
class test2{
abc :=0
}
Code: Select all
tes:=new test()
Msgbox % tes.abc
class test{
__new()
{
this.abc:=1
this:=new test2()
this.abc:=0
}
}
class test2{
abc :=0
}
Code: Select all
var := new A
MsgBox, % var.abc
return
class A
{
__New() {
this.abc := "Hello"
this := new B ; does not call A.__Delete as "this" is not the last reference to the object
this.abc := "World"
; B.__Delete is called in this case, "this" is the only reference to the object derived from B[class]
}
__Delete() {
MsgBox, % "Instance of class " this.__Class " deleted"
}
}
class B
{
__Delete() {
MsgBox, % "Instance of class " this.__Class " deleted"
}
}
Like any other parameter, this is an ordinary local variable. Consider this example from the documentation, which shows a method implemented "manually":Method definitions look identical to function definitions. Each method has a hidden parameter named this, which typically contains a reference to an object derived from the class.
Source: Objects
Code: Select all
; Create an object.
thing := {}
; Store a value.
thing.foo := "bar"
; Create a method by storing a function reference.
thing.test := Func("thing_test")
; Call the method.
thing.test()
thing_test(this) {
MsgBox % this.foo
}
Users browsing this forum: burque505 and 8 guests