1 A named function expression must scope its name to its own body: the name is 2 visible inside the function (for self-recursion) but must not be declared in the 3 enclosing scope. Declaring it there leaked the name and shifted the local slots, 4 so a `let`/`const` initialised by the expression was left uninitialised and its 5 first use raised "Can't access lexical declaration 'x' before initialization". 6 7 -- Testcase -- 8 const ok = !function self() { return false; }(); 9 print(ok, "\n"); 10 11 let fact = function rec(n) { return (n > 1) ? n * rec(n - 1) : 1; }; 12 print(fact(5), "\n"); 13 14 print((type(self) == "function" || type(rec) == "function") ? "leaked" : "clean", "\n"); 15 -- End -- 16 17 -- Args -- 18 -R 19 -- End -- 20 21 -- Expect stdout -- 22 true 23 120 24 clean 25 -- End --
This page was automatically generated by LXR 0.3.1. • OpenWrt