<!doctype html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<meta charset="UTF-8"/>
<title>Document</title>
</head>
<body>
<script>
var test=(function(a){
this.a=a;
return function(b){
return this.a+b;
}
}(function(a,b){
return a;
debugger;
}(1,2)));
console.log(test(4))
//结果是输出5 求解?
</script>
</body>
</html>
Memory
The original formula is simplified to:
After this sentence is executed,
test
is actuallyAnd at this time
this.a
is equal to1
. Therefore the result oftest(4)
is5
Obviously it’s 5
Breakdown
If you still don’t understand this, you have to learn the basics
First we need to understand the variable test. Test is actually a function, as follows
The outer part is a function that is executed immediately. First,
The result of this part is 1, that is to say, the code can be simplified to:
In the above code,
a=1
, therefore, in test(4), we get: