💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
11, ~~~ /* * 变量提升 * var ary; * fn = aaafff000; * var res; */ var ary = [1, 2, 3, 4];//=>ary=bbbfff111 [ARY全局变量] [0,2,3,4] function fn(ary) { /* * 形参赋值:ary=bbbfff111 [ARY是私有变量] */ ary[0] = 0; ary = [0];//=>ary=bbbfff222 [0(100)] ary[0] = 100; return ary; //=>return bbbfff222 } var res = fn(ary);//=>res=fn(bbbfff111)=bbbfff222 console.log(ary);//=>[0,2,3,4] console.log(res);//=>[100] ~~~ 12 ~~~ 1.function fn(i) { 2. return function (n) { 3. console.log(n + (i++)); 4. } 5.} 6.var f = fn(10); 7.f(20); 8.fn(20)(40); 9.fn(30)(50); 10.f(30); /* /!* * 变量提升 * fn = AAAFFF000 * var f; *!/ function fn(i) { /!* * 第一次FN执行 * i = 10 (11) (12) * * return BBBFFF111 (返回的小函数) *!/ /!* * 第二次执行FN * i=20 (21) * return BBBFFF222; *!/ return function (n) { /!* * 第一次执行F(20) * n=20 * 20+(i++) 不管是否加小括号都是先算20+i =>30 *!/ /!* * 第二次执行小函数(40) * n=40 * 40+20++ =>60 *!/ /!* * BBBFFF111的第二次执行(30) * n=30 * 30+i++ =>41 *!/ console.log(n + (i++)); } } var f = fn(10);//=> f=fn(10)=BBBFFF111 f(20);//=>30 fn(20)(40);//=>60 fn(30)(50);//=>80 f(30);//=>41*/ var i = 10; function fn() { return function (n) { console.log(n + (++i)); } } var f = fn(); f(20);//=>31 fn()(20);//=>32 fn()(30);//=>43 f(30);//=>44 ~~~