var a = fun(0); a.fun(1); a.fun(2); a.fun(3);
1、fun(0)时,第一个参数n为0,第二个参数o未设置,console.log(o)为undefined,return值为:
{fun:function(m){returnfun(m,n);//n为0}2、a.fun(1);m=1,代入上方return,得出新的return值为fun(1,0),执行得出console.log(0),return值为:
//fun(1,0)return值为:{fun:function(m){returnfun(m,n);//n为0}3、a.fun(2);m=2,代入上方return,得出新的return值为fun(2,0),执行得出console.log(0),return值为:
//fun(2,0)return值为:{fun:function(m){returnfun(m,n);//n为0}4、a.fun(3);m=3,代入上方return,得出新的return值为fun(3,0),执行得出console.log(0)
var b = fun(0).fun(1).fun(2).fun(3);
当执行到fun(0)时,与前面a一样,第二个参数未设置,console.log(o)为undefined;return值为:
{fun:function(m){returnfun(m,n);//n为0}当执行到fun(0).fun(1)时,m为1,代入上方return,得出新的return值为fun(1,0),执行fun(1,0),console.log(0),return值为:
//fun(1,0)的return值为:{fun:function(m){returnfun(m,n);//n为1}当执行到fun(0).fun(1).fun(2)时,m为2,代入上方return,得出新的return值为fun(2,1),执行fun(2,1),console.log(1),return值为:
//fun(2,1)的return值为:{fun:function(m){returnfun(m,n);//n为2}当执行到fun(0).fun(1).fun(2).fun(3)时,m为3,代入上方return,得出新的return值为fun(3,2),执行fun(3,2),console.log(2);
var c = fun(0).fun(1); c.fun(2); c.fun(3);
当fun(0)时,与前面b一致,undefined;
当fun(0).fun(1)时,与前面b一致,console.log(0);
c=fun(0).fun(1);return为:
{fun:function(m){returnfun(m,n);//n为1}因此c.fun(2)就是fun(0).fun(1).fun(2),与前面b一致,console.log(1);
因此c.fun(3)就是fun(0).fun(1).fun(3),m=3,代入上方return,得出新的retrun:fun(3,1);
得出结果console.log(1) |