title: Typescript function using recursion and yield keyword to pull out nested lists
body: <p>I'm trying to rewrite a C# function that uses <code>yield</code> and recursion to pull out instances of a class out of nested lists into a single list.</p>
  
  <p>This is the C# function:</p>
  
  <pre><code> public static IEnumerable&lt;TargetObject&gt; GetRecursively(params TargetObject[] startingObjects)
   {
      foreach (TargetObject startingObject in startingObjects)
      {
          yield return startingObject;
          if (startingObject.InnerObjects != null)
              foreach (TargetObject innerObject in startingObject.InnerObjects.ToArray())
                  foreach (TargetObject recursiveInner in GetRecursively(innerObject))
                      yield return recursiveInner;
       }
   }
  </code></pre>
  
  <p>Being that javascript doesn't reliably support <code>yield</code> across browsers, how can I simulate it in this complex function?   </p>
  
  <pre><code>function getRecursively(...startingObjects: TargetObject[])
  {
      return function () {
             ??
      }
  }
  </code></pre>