How to use nested functions as generator in javascript (using "inner" yields)
<pre><code>&lt;script&gt;
function * d1 (p)  {
    p-=1;
    yield p;
    p-=2;
    yield p;
}

var g=d1 (9);
var h;
console.log((h=g.next()).value+','+h.done+';');
console.log((h=g.next()).value+','+h.done+';');
console.log((h=g.next()).value+','+h.done+';');
&lt;/script&gt;
</code></pre>

<p>gives  8,false; then 6,false; then undefined,true;
whereas</p>

<pre><code>&lt;script&gt;
function * d2 (p)     {
    function * d1 (p)     {
        p -=1 ;
        yield p;
        p -=2 ;
        yield p;
    }
    d1(p);
}
var g=d2 (9);
var h;
console.log((h=g.next()).value+','+h.done+';');
console.log((h=g.next()).value+','+h.done+';');
console.log((h=g.next()).value+','+h.done+';');
&lt;/script&gt;
</code></pre>

<p>gives me three times undefined,true;</p>

<p>As I want the hidden structure of d1 (as inner-function), how can I proceed to still have the same result as on the first sample?</p>