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?