1.yield语句:
<script type="application/javascript; version=1.7"> function generator() { var i = 0; while(i<10) { //产生输出,这里的yield相当于return yield i; i++; } } //获取产生器 var g = generator(); //迭代 for(var j=0; j<10; j++) { document.write(g.next()+"<br>"); } </script>
2.with语句
有了 With 语句,在存取对象属性和方法时就不用重复指定参考对象,在 With 语句块中,凡是 JavaScript 不识别的属性和方法都和该语句块指定的对象有关。With 语句的语法格式如下所示:
With Object {
Statements
}
对象指明了当语句组中对象缺省时的参考对象,这里我们用较为熟悉的 Document 对象对 With 语句举例。
<script>
var rightNow = new Date();
with(rightNow) {
document.write(getDay()+"<br>");
document.write(getMonth()+1+"<br>");
document.write(getFullyear()+"<br>");
}
</script>
等价于:
<script>
var rightNow = new Date();
document.write(rightNow.getDay()+"<br>");
document.write(rightNow.getMonth()+1+"<br>");
document.write(rightNow.getFullYear()+"<br>");
</script>