0

I have written below code:

<script type="text/javascript">
function testGenerator()
{
yield "first";
document.write("step1");
yield "second";
document.write("step2");
yield "third";
 document.write("step3");
 }
 var g = testGenerator();
document.write(g.next());
document.write(g.next());
 </script>

My desired output: step1step2 But the above code show nothing on my html. Could any one help me to figure out what the mistake I have done here.

Thanks

1
  • 1
    yield is not supported in ES5. Generators will be available in ES6 (which probably takes a long time to be picked up by browsers...). Commented Nov 10, 2012 at 18:05

1 Answer 1

2

Generators/iterators are currently only supported by Firefox, and to use them you need to change your script tag's type attribute to "text/javascript;version=1.7".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.