LWLogan Won-Ki Leeinloganlee.hashnode.dev·Oct 25, 2022 · 1 min readJavaScript Y combinator and Z combinatorNote that this topic is a sub-set of lambda calculus. First how to prove that Y combinator is a fixed-point combinator: Y f = (lg. (lx. g (x x)) (lx. g (x x))) f = (lx. f (x x)) (lx. f (x x)) = l(lx. f (x x)). f (x x) = f ((lx. f (x x)) (...00
LWLogan Won-Ki Leeinloganlee.hashnode.dev·Oct 24, 2022 · 1 min readJavaScript Closure gotchas by reference not valueClosure sometimes behave undesirably, especially when you want to get by value and not by reference. Consider function outer() { let arr=[{accumulated:-1},{accumulated:-2},{accumulated:-3}]; let i; for (i=0; i<3; i++) { arr[i]["acc...00
LWLogan Won-Ki Leeinloganlee.hashnode.dev·Oct 23, 2022 · 1 min readJavaScript how to create persistent variableFirst method is to return a function inside parent function. Note that the inner function has access to private property of parent. const incr=(function(v) { return function() { return ++v; } })(100); console.log(incr()); //101 consol...00
LWLogan Won-Ki Leeinloganlee.hashnode.dev·Oct 23, 2022 · 1 min readJavaScript partial functionsConsider (https://jsfiddle.net/h9jz2yfs/) // currying function who(func) { let profile=''; return function(name) { profile+=`my name is ${name} `; return function(age) { profile+=`and i'm ${age} years old `; return f...00
LWLogan Won-Ki Leeinloganlee.hashnode.dev·Oct 23, 2022 · 1 min readJavaScript Auto-bound behavior of arrow functionsConsider class c { a=1; autoBound = () => {console.log(this.a);} } const C=new c(); const {autoBound}=C; console.log(autoBound); autoBound(); Output () => {console.log(this.a);} 1 As you can see, even when autoBound has been extracted out f...00