Call function outside class in same script

What is the proper way to call a function outside the class. The example code here would give the “unknown identifier” error.

   Class UnitInfo{
     function DemoOne(){
      Demo2();
     }
   }
    
   function Demo2(){
    
   }

After reading Yoerick answer, I did some testing. And found out that using GetComponent I could call a function that was not in a custom class. I will not be using this methods myself, as for my project I can work around the need by working outside the class. This strikes me as bad practice, but it is possible.

var test : someScript; //Name of the script itself

function Start(){
 test = GetComponent(someScript);


 for (var i : int = 0; i < 9; i++){
     Units *= new UnitInfo();*

Units_.Init( departmentSlots*, i, test );
}*_

}

class UnitInfo{

function Init(type : int, slotNum : int, test : operatorScript){
test.Test();

}
}

function Test(){
Debug.Log(“Test Called by class”);
}

Something like this is just not possible (or at least not in C# or VB), a function always has to be inside a class.

You could make a second class and declare the function over there. Make sure it’s a PUBLIC function, because by default a function is private (this means it’s only known to the class it’s inside of), then instantiate a reference to that class and call the function on the object.

Class SomeClass
{
    SecondClass a;
    a.SomeFunction();
}

Class SecondClass
{
    public void SomeFunction()
    {
        //function stuff here
    }
}

Edit: just in case you’re wondering why it’s not possible to declare a function outside of a class, give this article a look:
http://blogs.msdn.com/b/ericlippert/archive/2009/06/22/why-doesn-t-c-implement-top-level-methods.aspx