Can't Eval js code with yield
Here's 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've seen the following examples:
http://forum.unity3d.com/threads/eval-yield-waitforseconds-javascript.248463/
http://unixpapa.com/js/sleep.html
but couldn't do it myself.
Can anyone point me in the right direction?
thank
edit: Thanks for the quick answers, but I ran into a new problem: while using the func () function. next (); twice i keep getting โhelloโ โhelloโ instead of โhelloโ goodbye โcan anyone help me figure out what i am doing wrong?
+3
source to share