1

When I open the Chrome console and input some reference to members of objects, Chrome will auto-complete the name of the member, as in the following picture:

enter image description here

And sometimes it also shows the preview value of the member, as shown by the red circle. But some other times, it does not show me the preview:

enter image description here

I wonder what causes the difference? In the two examples above, both isActive and stretch are defined on the object by get-accessors. My understanding is that, since Chrome is able to show me the preview value of isActive, it must have execute the corresponding get-accessor (which is a very simple one in this case) to obtain the return value, but since it does not show me the preview for stretch (of which get-accessor consists of much longer and deeper codes), maybe, because the code involved is more complex, Chrome decide not to finish the whole execution and thus not showing me the preview?

Mu-Tsun Tsai
  • 2,348
  • 1
  • 12
  • 25
  • 1
    Chrome performs eager evaluation preview only if there are no side-effects so the second getter must be doing something that doesn't pass the check. We would have to see and compare the code to answer why. – wOxxOm Nov 04 '19 at 04:27
  • @wOxxOm I'm afraid that showing the code for the second getter is not quite feasible as it is a really complicated process. But can you explain or give reference on what would be consider a "side-effect"? Through experiment, I figured that "generating console output" and "setting values into variables" are two such things that will block the preview, and I would like to know what else are there. – Mu-Tsun Tsai Nov 04 '19 at 05:17
  • @wOxxOm OK, I guess I found what I need: https://stackoverflow.com/questions/8129105/javascript-closures-and-side-effects-in-plain-english-separately/8129277#8129277 – Mu-Tsun Tsai Nov 04 '19 at 05:33

0 Answers0