Hello

I am trying to learn more about coding object oriented JavaScript. Here is a situation that has me confused.

Code:
<html>
<head>

<script language="JavaScript">

function test()
{
   test = new classExample();
   test.publicFunction();
}

function classExample()
{
   this.publicFunction = function()
   {
      alert("publicFunction");
      alert( this );
      this.secondPublicFunction();
      privateFunction();
   }

   privateFunction = function()
   {
      alert("privateFunction");
      secondPrivateFunction();
      alert( this );
      this.secondPublicFunction();
   }
   
   secondPrivateFunction = function()
   {
      alert("secondPrivateFunction");   
   }
   
   this.secondPublicFunction = function()
   {
      alert("secondPublicFunction");
   }
}

</script>
</head>

<body>

<a href="javascript: test()">Test</a>

</body>
</html>
In the example I am trying to have a function within a class (what I am calling a JavaScript class) call another function. I am using this. to make functions public. Without putting the this. to me means it is private.

The situation I am trying to get help in understanding is that within a class, I thought all functions could call each other. In this example, that is not true. Once in the privateFunction, I can not call any other public function. I can call other private functions but I get an error stating “this.secondPublicFunction is not a function” if I call a public function.

Does anyone know why privateFunction() can not call secondPublicFunction()? I also find it odd that when I do an alert from the private function, this is referring to Window. When I do an alert from the public function, this refers to the Object, which is what I expected.

Thanks in advance for your time.