Brett Patterson skrev:
I like that explanation. I get it now. Thanks. One more quick question though, what is a let-block, in general? Thanks. That really does make it a lot easier to understand.

Brett

Normally JavaScript does not have block scope.

var foo = 1;
{
    foo = 2;
}
alert(foo); // will give you 2

Let-blocks will provide block-scope on an opt in basis:

var foo = 1;
{
    let foo = 2;
    alert(foo); // 2
    let bar = 3;
}
alert(foo); // 1
alert(bar); // undefined

Block scope is one feature that makes it easy to write interoperable code. My variables won't mess with your variables. Today we use function scope to accomplish the same thing:

var foo = 1;
(function() {
    var foo = 2;
    alert(foo); // 2
})() // last parenthesis invokes anonymous function
alert(foo); // 1


Let blocks are really handy in for loops:

var i = "Hi there";
for ( let i = 0; i < 10; i++) {
    alert(i); // 0 - 9
}
alert(i); // "Hi there"

Self executing functions have another kind of power through closures and possible return values, so the two do not completely overlap.

More info on the "New in JavaScript 1.7" article on MDC.


Lars Gunther



*******************************************************************
List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm
Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm
Help: [EMAIL PROTECTED]
*******************************************************************

Reply via email to