javascript笔记04:let语句 和 yield语句 和 with语句

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语句

<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>

 

你可能感兴趣的:(JavaScript)