1. What is the difference between a nested function inside a function and a method function inside an object?
2. Use of returnFunction F1 () {
var n=999;
Nadd=function () {n+=1}
function F2 () {
alert (n);
}
return F2;
}
var result=f1 ();
Result (); 999
Nadd ();
Result (); 1000
Summary: Nadd=function () {n+=1} did not return a return value but successfully returned n+=1;
3. The use of closures is a function inside a nested function to get a local variable, or a function inside return returns a local variable is re-assigned to the new variable. ①: Instead of using a function inside a function, it returns the local variable return directly inside the function. var = function data () {
var brith = 999;
return brith;
}
var son = age ();
alert (son); ②: Get local variables in traditional tutorials, and then set up a function inside the function. var sum = (function add () {
var plus = 0;
return function A () {return plus + = 1};
})();
function MyFunction () {
document.getElementById ("Demo"). InnerHTML = SUM ();
Console.log (sum);
}
JS closed package to solve the problem, I hope someone pointed