Help! "Cant Add Script" error is weird

Ok, so I have a javascript class that I wrote:

testClass.js:

class testClass
{ 
   var health : float;
   
   function doStuff()
   {
     Debug.Log("function called.");   
   }
}

Now when I try to add it to an empty game object, it says “Can’t add script behavior testClass. The script needs to derive from Monobehavior!”

So then I change it to this, and I can add it to the game object:

class testClass extends MonoBehavior
{ 
   var health : float;
   
   function doStuff()
   {
     Debug.Log("function called.");   
   }
}

Now I have another script attached to the game object to test the interaction of the class:
testReaderClass.js

function Start ()
{ 
   var newTestClass : testClass = new testClass (); 
   newTestClass.health = 5; 
   print (newTestClass.health);
   newTestClass.doStuff();
}

And I get the following warning message:

What does this mean? Could someone please shed some light on this?

ALSO: After I add the testClass.js to the game object, if I go back and delete “extends MonoBehavior” then I can have the class attached to the game object, and I get no warning message. Why is this?

This means you can´t create an instance of a MonoBehavior class using the constructor, you have to attach it to a game object and let the engine create the instance.

Don´t inherit from monobevhior, don´t attach it to a game object, then attach the script with the Start function you showed to a game object.

Ahhhhhh, ok it makes sense now. Thanks Dart for the quick reply. Cheers!