For me, "This" is just a way to prevent a conflict between member names and function parameter names:
Code: Select all
type vector
dim as single x, y
declare constructor()
declare constructor(x as single, y as single)
declare sub set(x_ as single, y_ as single)
declare sub print()
end type
constructor vector()
'nothing
end constructor
'this works :-)
constructor vector(x as single, y as single)
this.x = x
this.y = y
end constructor
'this sucks, but this works as well :-)
sub vector.set(x_ as single, y_ as single)
x = x_
y = y_
end sub
sub vector.print()
..print str(x)& "," & str(y)
..print str(this.x) & "," & str(this.y) 'the same
end sub
var v1 = vector(10.0, 13.0)
v1.print
dim as vector v2
v2.set(3.0, 4.0)
v2.print
sleep
Too late :-)
In python "This" is called "self", and it is required to use. You can recognize a python coder's keyboard by these 4 worn out keys :-)
It can also be used on the members functions, like this bugged code (segfault):
Code: Select all
sub vector.print()
this.print()
end sub