this pointer question

From: Jayme Pechan (jayme.pechan_at_whitefeld.com)
Date: 02/25/05


Date: Fri, 25 Feb 2005 13:41:19 -0800

I noticed something that seems strange to me regarding the 'this' pointer
for objects. Note the code below. The output is:

b null
strange problem.

how come b.Success == null but this.Success inside the b object is not null
but instead equal to itself? I did set it = to null before running the
function.

The remarks in Visual Studios JScript reference says the following:
Remarks
The this keyword is typically used in object constructors to refer to the
current object.

Is it possible that unlike C++, the this is only valid in the constructor
and not other functions? It worked for the a.Success one.

var a = new Object();
var b = new Object();
a.Process = function()
 {
  this.Success();
 }
b.Process = function()
 {
  if (this.Success == null)
   WScript.echo("This null");
  if (b.Success == null)
   WScript.echo("b null");

  if (this.Success == b.Process)
   WScript.echo("strange problem");
  return;
 }
a.Success = b.Process;
b.Success = null;

a.Process();

-----------------------------------------
Next I tried the following script:

I got:
strange problem
stranger problem

var a = new Object();
var b = new Object();
var c = new Object();

a.Process = function()
 {
  this.Success();
 }
b.Process = function()
 {
  if (this.Success == b.Process)
   WScript.echo("strange problem");
  b.Success();
 }
c.Process = function()
 {
  if (this.Success == c.Process)
   WScript.echo("stranger problem");
 }
a.Success = b.Process;
b.Success = c.Process;
c.Success = null;
a.Process();

Am I missing something obvious here?

It seems like c.Success = null is the same as c.Success = c.Process perhaps
because it is the first variable in the object?



Relevant Pages

  • Problem setting object variables in PHP4
    ... I am having a very strange problem. ... I wrote a program in php 4.3.10 ... var $x; ... // Set functions force input to an integer ...
    (comp.lang.php)
  • Re: this pointer question
    ... > strange problem. ... > The remarks in Visual Studios JScript reference says the following: ... > The this keyword is typically used in object constructors to refer to the ... var a =; ...
    (microsoft.public.scripting.jscript)
  • Re: Thunderbird inadvertent drag & drop triggered
    ... strange problem. ... When reading newsgroup messages the pointer will ... will still get the D&D cursor when selecting a Subject. ...
    (Ubuntu)
  • Re: Thunderbird inadvertent drag & drop triggered
    ... strange problem. ... When reading newsgroup messages the pointer will ... will still get the D&D cursor when selecting a Subject. ...
    (Ubuntu)
  • Weird cursor problem in X11
    ... I am having a strange problem in X11 that I have not been able to ... frozen cursor will go away after a couple minutes, ... pointer is gone, it will reappear in a different spot on the screen. ...
    (Debian-User)