Definition of Script.function() depends on Script.function()...

I'm wanting to create a loop like so:

function foo()
{

yield WaitForSeconds(1);

...

foo();

}

But I get the error

BCE0070: Definition of 'Script.foo' depends on 'Script.foo' whose type could not be resolved because of a cycle. Explicitly declare the type of either one to break the cycle.

I had a look around for the error code and had a read of the yield pages on the docs but I can't make sense of it. How can I create a loop like the above?

Just create it as an infinite loop

function foo()
{
    while(true)
    {

        yield WaitForSeconds(1);

        ...
    }
}

Generally you shouldn't use recursion unless you actually need it, but just to answer the specific question here, the type of a coroutine is IEnumerator. So you can use

function foo() : IEnumerator

to fix the error message, though using an infinite loop is better in this case.

acturally, I have found a solution

http://forum.unity3d.com/threads/6906-recursive-calling

here, we can write javascript like this~

function ToJSON(obj : Boo.Lang.Hash) : String {	 

what unity need just a return Type