How to pass arguments to function referenced by variable

Question:

I have a function ‘foo’ and a variable ‘$foo’ referencing it.

I can call $foo without args, but how can I pass parameters? This does not work:

Actually the goal is to write such code:

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 !

Source:

How to pass arguments to function referenced by variable by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply