What is "this?"
Here's an OpenLaszlo question that bothered me when I first started, although I have a better feel for how things work now.
In the OpenLaszlo "dashboard" demo, there is a class called
Q: When the audioviewer method says
A: I added debug code
I did not understand what the
I was thinking in terms of Java. There, you write methods and properties for a class. When you instantiate a class, you do not add things inside it. The only way you can affect the instance that you are creating is by passing arguments to it. (Possibly that is just what you are doing when adding tags inside the
So in Java terms, when I put a
In the OpenLaszlo "dashboard" demo, there is a class called
music
in file musiclib.lzx. The music
class has a view called audioviewer
; that view has a method playMedia
. Q: When the audioviewer method says
this.play()
, to what does "this" refer? Is it an instance of music
, audioviewer
, the canvas in which music
is instantiated, or what?A: I added debug code
Debug.write("this is " + this);
right after this.play()
and ran it; output is: this is $t8 id: audioviewer
. So, "this" means audioviewer
.I did not understand what the
view
tag was doing, initially, or any of the other tags for that matter. I was thinking in terms of Java. There, you write methods and properties for a class. When you instantiate a class, you do not add things inside it. The only way you can affect the instance that you are creating is by passing arguments to it. (Possibly that is just what you are doing when adding tags inside the
canvas
tag - I'm still not clear about what really happens there.)So in Java terms, when I put a
view
tag inside the canvas
tag, it doesn't make sense that I've just declared an instance of a view object (instance of LzView) inside the canvas
object. With Laszlo I get the feeling that this is what is happening. Currently, whenever I see a tag like <view>
or <canvas>
, I associate it with an instance of a class (LzView or LzCanvas). I need to do more reading about this!
0 Comments:
Post a Comment
<< Home