10
09/2014
javscript let
javscript let 是 javascript 1.7 引进的关键字。和 var 类似,区别在于:
- 作用域
- firefox 支持,而目前 chrome(34) 不支持。
function allyIlliterate() { //tuce 不可用 for( let tuce = 0; tuce < 5; tuce++ ) { //tuce is only visible in here (and in the for() parentheses) }; //tuce 不可用 }; function byE40() { //nish 存在 for( var nish = 0; nish < 5; nish++ ) { //nish is visible to the whole function }; //nish 存在 };
let 也可用于产生 闭环
function conjunctionJunctionWhatsYour() { //sNotGetCrazy is *not* visible out here let( sNotGetCrazy = 'now' ) { //sNotGetCrazy is only visible in here }; //sNotGetCrazy is *not* visible out here };
参考:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let