getify / You-Dont-Know-JS

A book series on JavaScript. @YDKJS on twitter.
Other
179.37k stars 33.48k forks source link

Possible codeblock issue. YDKJS: Async & Performance>Ch1: Asynchrony: Now & Later #868

Closed hungLink closed 8 years ago

hungLink commented 8 years ago

https://github.com/getify/You-Dont-Know-JS/blob/master/async%20%26%20performance/ch1.md

Right after the paragraph that starts with "Other examples where the compiler reordering could create observable side effects", there is the following code inside a codeblock:

function foo() {
    console.log( b );
    return 1;
}

var a, b, c;

// ES5.1 getter literal syntax
c = {
    get bar() {
        console.log( a );
        return 1;
    }
};

a = 10;
b = 30;

a += foo();             // 30
b += c.bar;             // 11

console.log( a + b );   // 42

I beleive lines 18 and 19 should be:

a += foo();             // 11
b += c.bar;             // 31
getify commented 8 years ago

those comments are the result of the console.log messages not the variables themselves.

hungLink commented 8 years ago

Ah. I see. Thank you.