1 Testing closure scopes. 2 3 4 1. Ensure that the declaring scope is retained in functions. 5 6 -- Expect stdout -- 7 Make function with x=1 8 Make function with x=2 9 Make function with x=3 10 x is 1 11 x is 2 12 x is 3 13 -- End -- 14 15 -- Testcase -- 16 {% 17 let count=0; 18 19 function a() { 20 let x = ++count; 21 print("Make function with x=", x, "\n"); 22 return function() { 23 print("x is ", x, "\n"); 24 }; 25 } 26 27 let fn1 = a(); 28 let fn2 = a(); 29 let fn3 = a(); 30 31 fn1(); 32 fn2(); 33 fn3(); 34 %} 35 -- End --
This page was automatically generated by LXR 0.3.1. • OpenWrt