Click to See Complete Forum and Search --> : "this" and that
JackTheTripper
04-02-2003, 01:11 PM
Hey guys. Newbie here and have a question.
I've never understood how to use the 'this' statement. Can anyone point me to an online tutorial on how to use?
Thanks
"this" is a statement that refers to an object.
havik
04-02-2003, 03:10 PM
more specifically, the object where this is, is the object this refers to. I don't think that made sense. :D
example:
<input type="text" name="test" onclick="clearField(this)">
- sending the argument 'this' to the clearField function would send a reference to the textfield 'test'.
Better?
Havik
Ice3T
04-03-2003, 12:52 AM
is there a diff between:
<input type=text onMouseOver="func1(this)">
function func1(that){
that.value=""}
<input type=text onMouseOver="func1()">
function func1(){
event.srcElement.value=""}
?
Scriptage
04-03-2003, 05:24 AM
I think you mean object orientated programming.
function someObject(x, y){
this.name = x;
this.colour = y;
this.display = displayObj;
return this;
}
function displayObj(){
with(this);
alert("Name: "+this.name+", Colour: " + this.colour);
return;
}
var objectX = new someObject("objectX","Blue");
objectX.display();
In the function someObject, this refers to the object. The variable objectX becomes a new instance of the class someObject, and therefore inherits the variables name and colour and the function display.
In the function displayObj, this refers to the object that called it, which in this case is objectX.
The values are loaded using the line...with(this);
Object Orientated Programming is the best use for using "this".
Regards.