Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The inner function creates a <a href="https://stackoverflow.com/questions/tagged/javascript+closure">closure</a>, capturing the variables in the scope it is defined in. So you already have what you're asking for...</p> <p>...whether that's a good idea or not is another matter. </p> <p>For starters, you're not actually <em>modifying</em> the value in the code you listed - you're assigning <code>$current_page</code> the same value it was already initialized with. </p> <p>But assuming you just omitted the code that you would normally use to pick a <em>different</em> value for <code>$current_page</code>, you need to ask yourself: is this really even <em>necessary</em>? You're performing a lookup based on an element ID and caching a reference to that element in a variable without knowing if or when you'll actually need it again. At best, this results in a potentially-unnecessary lookup; at worst, it can result in a memory leak. Why not just keep track of the ID itself, and look up the element when and where you actually need it? Don't worry about performance until you actually encounter a performance <em>problem</em>... or you may find that your premature optimization has caused more problems than it solves.</p> <p>Same goes for <code>$home_page</code>, <code>$portfolio_page</code> and <code>$about_page</code> - you're making your page load (slightly) more slowly on the off-chance that you'll need a reference to those elements later on, when you could just as well look them up as-needed.</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. This table or related slice is empty.
    1. 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