Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>EDIT: THERE IS AN "OFFICIAL" ANSWER IN THIS LINK: <a href="http://code.google.com/p/closure-compiler/issues/detail?id=410#makechanges" rel="nofollow">http://code.google.com/p/closure-compiler/issues/detail?id=410#makechanges</a></strong></p> <p>I think an assignment to a variable, followed immediately by usage of that variable, can be inlined. However, if there is any statement in between that cannot be proven to be free of side-effects, then the compiler won't inline it.</p> <p>In your case, assignment to variable "start" is separated from the usage of "start" only by the assignment statement to "end". However, this statement is free of side-effects since Math.max is an internal function and the compiler knows that it is side-effect-free.</p> <p>However, in your case, assignment to variable "end" is separated from the usage of that variable by a statement, which is an assignment of "start" to a property. Now, I believe that the compiler does not assume that merely assigning to a property is always side-effect-free; that is because some properties, when assigned, actually cause different behavior, or change global state (such as RegExp). In some systems, property assignments actually trigger certain system-specific features (e.g. hardware interface) that may in-turn contain side-effects.</p> <p>That is why, sometimes, when you have code like this:</p> <pre><code>foo.bar = 1; foo.bar = 2; foo.bar = 3; </code></pre> <p>The compiler won't eliminate the first two statements since assignment to "bar" may have side effects.</p> <p>So, in your question, the variable "end" cannot be inlined because the statement <code>tb.selectionStart = start;</code> may have side effects (perhaps only in wierd cases).</p> <p><strong>If you make "tb" a local variable, or something that the compiler has complete control of (e.g. a simple object: <code>var tb = {};</code>), then you'll find that the compiler inlines all of the assignments just fine.</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload