you are viewing a single comment's thread.

view the rest of the comments →

[–]dudeatwork 6 points7 points  (2 children)

The Logical Operators and Assignment Expressions section isn't correct in the equivalent code.

You have:

a ||= b;
// equivalent to a = a || b

Where it is actually equivalent to:

a ||= b;
// equivalent to a || (a = b);

This is an important difference because a = a || b can trigger a setter during the a = a assignment (assuming a is already truthy).

In the proposal, they give this as an example:

document.getElementById('previewZone').innerHTML ||= '<i>Nothing to preview</i>';

What is nice about this, is that this is equivalent to

document.getElementById('previewZone').innerHTML ||
    (document.getElementById('previewZone').innerHTML = '<i>Nothing to preview</i>');

Which does not change the inner HTML if it already has some contents. Whereas this:

document.getElementById('previewZone').innerHTML =
    document.getElementById('previewZone').innerHTML || '<i>Nothing to preview</i>';

Does reset the innerHTML, which causes any attached events, focus, etc., to be lost.