I came upon this simplified example of a memoization function in JavaScript. It's then used to memoize a function that adds 2 to whatever number is passed in. When I saw this, it didn't seem obvious that the memoize function would continue to store the cache variable after being ran since it's not a property of memoize, just (seemingly) an ordinary local variable. Shouldn't it be overridden whenever memoize is called via plusTwo? Where can I find out more about this behavior in JavaScript?  var memoize = function(function_) {     var cache = {};      return function() { // What does this function do?          //makes a string out of the arguments of the function that was passed in         var arg_str = JSON.stringify(arguments);          /*          sets the cache value for the arguments to the value that was already calculated          (if available) or calculates the value for the passed in function on its         */         cache[arg_str] = cache[arg_str] || function_.apply(function_, arguments);          console.log(cache);         // returns the calculated (or cached) value         return cache[arg_str];     }; };  var plusTwo = memoize(function (x) {     return x + 2; });  module.exports = memoize, plusTwo;
How would you explain JavaScript closures to someone with a knowledge of the concepts they consist of (for example functions, variables and the like), but does not understand closures themselves?  I have seen  given on Wikipedia, but unfortunately it did not help.
Remote Linux server to remote linux server dir copy. How? What is the best way to copy a directory (with sub-dirs and files) from one remote Linux server to another remote Linux server? I have connected to both using SSH client (like Putty). I have root access to both. Safari autofill multiple e-mail adresses What was Mr. Anderson (Neo) selling on discs to Choi? The name of the boy vs.The boy's name Which one is correct or are both correct?     The boy's name is nice.   The name of the boy is nice.     I'm really confused these two sentences?  Which one is more suitable? What are the differences between sudo, su, visudo, chroot, and gksu? What are the differences between sudo, su, visudo, chroot, and gksu ? If in Pete's World there's no Doctor, how is there a Torchwood? calculate slope for a road network I am working on a road network for routing operations using postgis and QGIS.    I am new to both of these tools and need to calculate the slope for each edge (by retrieving the Z value for the start and end node for the edge from a raster). Any ideas of the best approach to this?   I know postgis can dump points and get the value from a raster, but can I get the slope attribute to the edge without breaking the network topology (with edges that have corresponding start/end nodes) using this method?   thanks How to print only last column? echo -e 'one two three\nfour five six\nseven eight nine' one two three four five six seven eight nine   how can I do some "MAGIC" do get this output?:  three six nine   UPDATE: I don't need it in this specific way, I need a general solution so that no matter how many columns are in a row, e.g.: awk always displays the last column. The very common beginner mistake is when you try to use a class property "statically" without making an instance of that class. It leaves you with the mentioned error message:     You can either make the non static method static or make an instance of that class to use its properties.   Why? I am not asking for solutions. I would be grateful to know what is the reason behind it. The very core reason!  private java.util.List&lt;String&gt; someMethod(){     /* Some Code */     return someList;             }  public static void main(String[] strArgs){                // The following statement causes the error. You know why..     java.util.List&lt;String&gt; someList = someMethod();          } “It can be very cold…” vs “It may be very cold…” It can be very cold in winters.   It may be very cold in winters.   What is the difference between these two sentences?  People say when may is used then it means that it may be cold in winters or it may not be cold in winters. In other words, may means 'not sure'.  So does that mean if can is used then it is 100% sure that it will be cold in winters? I'm using using algorithm2e package with the following settings:  \usepackage[ruled,vlined,linesnumbered,noresetcount]{algorithm2e}   But for some subset of algorithms in the same document, I want to use this setting:  \usepackage[boxed]{algorithm2e}   Is there a way to override the default setting just for a subset?  I found a similar question:  Here newenvironment is used to override the default setting of an option. But I want to override the option itself.  I wish there was a way to load a package several times with different options for each instance. How did humans and vulcans communicate in Star Trek: First Contact? Can you attack with different weapons using Extra Attack? The fighter's  feature (PHB, p. 72) says:     Beginning at 5th level, you can attack twice, instead of once, whenever you take the Attack action on your turn.   Assuming I am holding two different weapons, and don't want to spend my bonus action on Two-Weapon Fighting, can I attack once with each weapon? How should I phrase an important question that I need to ask a professor? When needing to ask a professor about something important and potentially delicate, what is an appropriate way to phrase the question or write the email?  Examples include:   Requesting a recommendation letter Asking for exceptions to policy (e.g., ignoring a course prerequisite, rescheduling an exam) Asking if you can do research with them, join a group, get into a program Scheduling a meeting, exam, or defense Letting them know about a change of plans Letting them know about a life event affecting your work or studies (e.g., wedding, funeral, sickness, vacation) Creating files in C++ Windows registry entries for default explorer view How to disable gedit side panel? How do i disable this stupid side panel of gedit, that somehow appeared? There is nothing in the settings or plugins. Tried rm -r -f ~/.config/gedit as well, with no success. I don't have big screen and i find it totally useless and eating up what little free space for editing documents i have. See Screenshot How to prove $ \prod_{d|n} d= n^{\frac{\tau (n)}{2}}$ how to prove:   $$ \prod_{d|n} d= n^{\frac{\tau (n)}{2}}$$   $\prod_{d|n} d$ is product of all of distinct positive divisor of $n$,  $\tau (n)$ is number (count)of all of positive divisor of $n$ Single word to denote date and time I want one word that means Date and Time. For example in "the date and time of the event will be announced later" I want to use single word instead of "date and time" When is "self" required?