Question:
I have a function ‘foo’ and a variable ‘$foo’ referencing it.
1 2 3 4 5 6 7 8 9 |
function foo { param($value) $value + 5 } $foo = foo $foo |
I can call $foo without args, but how can I pass parameters? This does not work:
1 2 3 |
$foo 5 $foo(5) |
Actually the goal is to write such code:
1 2 3 4 5 6 7 |
function bar { param($callback) $callback 5 } bar(foo) |
Answer:
The problem is when you do
$foo = foo
You put the result of the function in the variable $foo, not the function itself !
Try this :
$foo = get-content Function:\foo
And call it like this
& $foo 5
Hope it helps !