Can I assign a function to a variable?

gooly

is it correct that I cannot assign a function to a variable - like:

     $h = {ID="x1";readStream=$Null;... }
     ...
     $h.readStream = function{ ... }

Thanks!

P.S. @ A.Wiechers: To me it would help a lot if ALL the Title has at first entry the prg.-langague the question is about!! For this question I have to open only needles hints which I would have been able to skip if e.g. "Can I assign a function to a variable for use within another function? 1" would start with "Python" - the entry of the tags do NOT filter the StackExchange-suggestions! This would even help to prevent duplicate entries just because the titles are similar!!

Gruntzy

You just need to use a scriptblock.

let's take a really simple example : I want to multiply two integers in my function :

just do something like :

$h = @ {ID="x1" ; DoStuff = $Null }
$h.DoStuff = { $args[0] * $args[1] }
# note that $h = @{ID="x1" ; DoStuff = {$args[0] * $args[1]} } works as well


# Invoke your block : 
& $h.DoStuff 6 7

# or 
$h.DoStuff.Invoke(6,7)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why can't I assign a function to a variable using prototype?

From Dev

Why can I assign the return value of a function that returns `const T&`, to a `T` variable but not to a `T&` variable?

From Dev

How Can I Assign a Function to a Function Pointer

From Dev

PHP - Can you assign a member function to a variable?

From Dev

Can't assign function result to a variable

From Dev

Why I could not assign a wordpress function to a variable?

From Dev

Why would I assign an anonymous function to a variable?

From Dev

Why I could not assign a wordpress function to a variable?

From Dev

Why would I assign an anonymous function to a variable?

From Dev

How can I assign an element to variable?

From Dev

How can I assign lineEdits to some variable?

From Dev

Can I conditionally choose which variable to assign to?

From Dev

How can I assign Cell Part as Variable?

From Dev

How can I assign an element to variable?

From Dev

can I assign "pass" keyword to a variable/name?

From Dev

How can I assign variable from json?

From Dev

Why can't I assign any variable to a function return value in pChart?

From Dev

Why can’t I assign values to a variable inside a named function expression with the same name?

From Dev

Why can't I assign my function reference to a matching variable? E2555 is raised

From Dev

Can I assign function based on the condition in jquery?

From Dev

Can I assign attribute to a function inside itself?

From Dev

Can I assign a nested function to a parameter of the parent function in Javascript?

From Dev

How to define a variable that is a function pointer that can assign other functions in c?

From Dev

Assign the result of a function to variable?

From Dev

How do I declare a function and then assign it to a variable in the same line?

From Dev

I cannot assign a value to a variable after call a function in javascript

From Dev

In tkinter how do I assign the entry function to a variable

From Dev

I cannot assign a value to a variable after call a function in javascript

From Dev

How do I assign a variable to a specific function output in python?

Related Related

  1. 1

    Why can't I assign a function to a variable using prototype?

  2. 2

    Why can I assign the return value of a function that returns `const T&`, to a `T` variable but not to a `T&` variable?

  3. 3

    How Can I Assign a Function to a Function Pointer

  4. 4

    PHP - Can you assign a member function to a variable?

  5. 5

    Can't assign function result to a variable

  6. 6

    Why I could not assign a wordpress function to a variable?

  7. 7

    Why would I assign an anonymous function to a variable?

  8. 8

    Why I could not assign a wordpress function to a variable?

  9. 9

    Why would I assign an anonymous function to a variable?

  10. 10

    How can I assign an element to variable?

  11. 11

    How can I assign lineEdits to some variable?

  12. 12

    Can I conditionally choose which variable to assign to?

  13. 13

    How can I assign Cell Part as Variable?

  14. 14

    How can I assign an element to variable?

  15. 15

    can I assign "pass" keyword to a variable/name?

  16. 16

    How can I assign variable from json?

  17. 17

    Why can't I assign any variable to a function return value in pChart?

  18. 18

    Why can’t I assign values to a variable inside a named function expression with the same name?

  19. 19

    Why can't I assign my function reference to a matching variable? E2555 is raised

  20. 20

    Can I assign function based on the condition in jquery?

  21. 21

    Can I assign attribute to a function inside itself?

  22. 22

    Can I assign a nested function to a parameter of the parent function in Javascript?

  23. 23

    How to define a variable that is a function pointer that can assign other functions in c?

  24. 24

    Assign the result of a function to variable?

  25. 25

    How do I declare a function and then assign it to a variable in the same line?

  26. 26

    I cannot assign a value to a variable after call a function in javascript

  27. 27

    In tkinter how do I assign the entry function to a variable

  28. 28

    I cannot assign a value to a variable after call a function in javascript

  29. 29

    How do I assign a variable to a specific function output in python?

HotTag

Archive