Having two functions one wrapping the other, how to pass a parameter down correctly? At the moment the console logging does not work.
const a = (v) => (v) => console.log(v);
a(2);
Having two functions one wrapping the other, how to pass a parameter down correctly? At the moment the console logging does not work.
const a = (v) => (v) => console.log(v);
a(2);
Passing a parameter in High order fn is easy as the value get set to closure
const a = v => () => {console.log(v)};
a(2)()
No matter how deep you go, parameter passed to fn
get set to closure
space when a fn
having a parameter v
either returns a fn
or executes a fn
which uses that parameter v
const a = v => () => () => () => {console.log(v)}
a(2)()()()
If you really want to work on two functions
const a = (v) => (a = v) => console.log(a);
a(2)()
What you did over there to define a lambda function within a function.
If you want it to work with a(2)
you need to excecture the inner function (meaning to add ()
at the end), like this:
const a = (v) => (() => console.log(v))();
a(2);
This (() => console.log(v))
is a function, when you add ()
at the end it's actually activating that function, and that's why what you did, didn't work.
You have two v
variables, and the inner one is shadowing the outer one since they have the same name. Unless you rename the inner v
, there's no way to access the outer v
from inside that function.