Here is my simplified code:
<html>
<body>
<button onclick="testRun()">Click me</button>
<script type="application/javascript" language='javascript1.7'>
function testRun() {
var txt = 'var func = function*() {console.log("hi");';
txt += 'yield true;';
txt += 'console.log("bye");';
txt += 'yield false;}';
eval(txt);
func().next();
func().next();
}
</script>
</body>
</html>
I keep getting the following error:
1.html:1 Uncaught SyntaxError: Unexpected token true
I have seen the following examples:
http://forum.unity3d.com/threads/eval-yield-waitforseconds-javascript.248463/
http://unixpapa.com/js/sleep.html
but haven't been able to do it myself.
can anyone direct me in the right direction?
thanks
edit: thanks for the quick answers but I have encountered a new issue: when using the func().next(); twice I keep getting "hi" "hi" instead of "hi" bye" can anyone help me understand what am i doing wrong?
Your code will work if you change it to: