求解js 的问题 为什么结果是5? 分析一下

<!doctype html>

<html>

<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>


呼唤远方
浏览 675回答 1
1回答

慕码人2483693

记let functionA = function (a) {&nbsp; &nbsp; this.a = a&nbsp; &nbsp; return function (b) {&nbsp; &nbsp; &nbsp; &nbsp; return this.a + b&nbsp; &nbsp; }}let argA = function (a, b) {&nbsp; &nbsp; return a&nbsp; &nbsp; debugger}(1, 2)// 实际上 argA 就等于 1,** 这个地方的 b 没有被用到 **则原式简化成:let&nbsp;test&nbsp;=&nbsp;functionA(argA)此句执行完后&nbsp;test&nbsp;实为function (b) {&nbsp; &nbsp; return this.a + b}// ** 这是一个带一个参数的函数,执行 test(4) 时 b 就是 4 **且此时&nbsp;this.a&nbsp;等于&nbsp;1。因此&nbsp;test(4)&nbsp;结果为&nbsp;5
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript