Together, we get better every day. It all adds up, and one day it will.

(a) can not say the JS key knowledge ~ immediately execute the function

(two) can not say the JS key knowledge ~ throttling and anti shake (test little sister topic)

(3) can not say the JS key knowledge ~ recursion and tail recursion (test little sister topic)

(4) can not say the JS key knowledge ~ closure (test little sister topic)

(5) javaScript key knowledge ~~~ singleton pattern (test little sister topic)

Hello, everyone. After a week of recursion. The test sister is back to basics (she dared to take off her shoes in my passenger seat. She takes off her cool goddess pose. This makes my heart a little bit of comfort, after all, did not live up to my pay these days.
But I found that there were other men courting my sister. What to do? I am a possessive man. Is this acceptable? To think of a way, let the little sister heart only I a person. Her private life can only have me to participate in, specific is: she can and I hand in hand, go shopping together, shopping, have a meal…….. And of course kiss………
As time went by, the idea of programming “closures” came to me. One of the features of “closures” is the ability to make properties of an object private !!!!
Let the little sister, hand in hand, eat, shopping….. These properties. I’m the only one who can access it.
Think of it as a function, create a function inside it, and return the function. When she gets a new date. The function that I return starts with me. Only I have access to all of the properties of the little sister function. This idea is so MT.

Let’s look at closures.

Closure functions: Functions declared in a function are called closure functions.
** Closure ** : An inner function can always access arguments and variables declared in its outer function, even after its outer function has been returned (end-of-life).

The pros and cons of closures

Local variables are resident in memory;
Can avoid the use of global variables, to prevent global variables pollution;
Can cause memory leaks (when a chunk of memory is occupied for a long time and not released)

The classic case of closures.

Case 1:

Function xiaojiejie(){var dubai = 'I love you '; // Xiaojiejie's activity object; Function wenwo(){console.log(' kiss me ')} return function(){// Anonymous function active object; console.log(dubai); wenwo(); } } var wo = xiaojiejie(); wo(); // I love you Pony brother, kiss meCopy the code

Case 2:

function xiaojiejie(x) { return function(y) { return x + y; }; } var duixiang1 = xiaojiejie(" xiao Ma ge "); Var duixiang2 = xiaojiejie(" I love you "); Console. log(duixiang1(" I love you ")); Console. log(duixiang2(" XXX ")); I love you XXXCopy the code

There is no perfect solution. As with this closure, one feature I’ve omitted is the ability to create multiple objects, each with its own unique memory address. Every different object that comes out of new has access to the attributes of the little sister. Case two, though, can be optimized to some extent by passing in the reference. But the little sister is hard to avoid being corroded in the metropolis. If we can’t solve this problem, little sister can be Aquaman. Think of here I cried, how to do? I want to let the little sister’s heart only me…….. Each great god helps a support a recruit………