function fun(n,o){
console.log(o);
return{
fun:function(m){
return fun(m,n);
}
};
}
var a= fun(0);
a.fun(1);
a.fun(2);
a.fun(3);
var b=fun(0).fun(1).fun(2).fun(3);
var c=fun(0).fun(1);
c.fun(2);
c.fun(3);
答案和解析在下面:
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
答案:
解析:
var obj = new Fun();
function fun(n,o){
console.log(o);
return{
fun:function(m){
return fun(m,n);
}
};
}
var a= fun(0);
//此时0作为参数传给n, n=0,o=undefined 输出undefined
a.fun(1);
//此时1作为参数传给m,n=0 return fun(m,n)后 n=1,o=0 输出0
a.fun(2);
//此时2作为参数传给m,n=0 return fun(m,n)后 n=2,o=0 输出0
a.fun(3);
//此时3作为参数传给m,n=0 return fun(m,n)后 n=3,o=0 输出0
var b=fun(0).fun(1).fun(2).fun(3);
//1.var b=fun(0) 此时0作为参数传给n, n=0,o=undefined 输出undefined
//2.var b=fun(0).fun(1) 此时1作为参数传给m, return fun(m,n)后 n=传进来的m=1,
// o=传进来的n=0,输出0
//3.var b=fun(0).fun(1).fun(2) 此时2作为参数传给m, return fun(m,n)后
// n=传进来的m=2,o=传进来的n=1,输出1
//4.var b=fun(0).fun(1).fun(2).fun(3);此时3作为参数传给m, return fun(m,n)后
// n=传进来的m=3,o=传进来的n=2,输出2
var c=fun(0).fun(1);//会前面两个就会第三个
c.fun(2);
c.fun(3);