Get the name of a method stored in a variable

MetalFoxDoS

I have some trouble with getting the name of a method stored in a variable... Here is an exemple of what I want :

Function MyObject(){
    this.actualMethod = this.thatName;
}

MyObject.prototype.thatName = function(){}

MyObject.prototype.getActualMethodName = function(){
    return this.actualMethod.name; /* This doesn't work since the function itself is anonymous, so this.actualMethod.name doesn't work... I want it to return "thatName" */
}

I tried to navigate through the prototype with my console, in vain... Is there a way to do this ?

Razem

You need to name the function:

MyObject.prototype.thatName = function thatName() {};

Or, as you mentioned, you can find its name in the prototype (but I wouldn't suggest you to do it):

for (var key in MyObject.prototype) {
  if (MyObject.prototype[key] === this.actualMethod) {
    return key;
  }
}

But why do you need this? Maybe there could be a better solution.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Java: call a method with name stored in variable

From

How to get a variable value if variable name is stored as string?

From Dev

Invoke function whose name is stored in a variable in bash

From Dev

Call a function whose name is stored in a variable

From Dev

How is a variable name stored in C?

From Dev

Swift: Print name of a function stored in a variable

From Dev

Call to a method stored in a variable in Typescript

From Dev

Dynamic table name variable in stored procedure

From Dev

How can I get the name of a variable type, when it's stored as String or Boolean?

From Dev

Get variable value by its name stored in another variable in powershell

From Dev

Selecting an object property by a name stored in a variable

From Dev

Stored procedure with @variable server name

From Dev

How to get XAML element by name stored in a string variable?

From Dev

Create a variable having name stored in a string variable

From Dev

Join with a table name stored in a variable in Rails 3.2

From Dev

How to get tag value from input XML where tag name is stored in a variable

From Dev

CallerInfo, get name of variable passed to method (like nameof)

From Dev

Calling a method (stored in a variable) in a closure

From Dev

Python: call a method with the name stored in a variable

From Dev

R: How to use $ when the name is stored in a variable?

From Dev

Get object dynamically with the name stored in a variable

From Dev

R : name of an object stored in a variable

From Dev

Get variable by its name, which is stored in another variable

From Dev

Separate $_GET information that is stored in a variable?

From Dev

javascript call a method with a name stored onto a variable

From Dev

Javascript - variable for method name?

From Dev

batch Get value of variable stored inside variable

From Dev

PostgreSQL Call a stored procedure with its name is into variable

From Dev

How to get the return value from an async method, stored in a Task variable

Related Related

  1. 1

    Java: call a method with name stored in variable

  2. 2

    How to get a variable value if variable name is stored as string?

  3. 3

    Invoke function whose name is stored in a variable in bash

  4. 4

    Call a function whose name is stored in a variable

  5. 5

    How is a variable name stored in C?

  6. 6

    Swift: Print name of a function stored in a variable

  7. 7

    Call to a method stored in a variable in Typescript

  8. 8

    Dynamic table name variable in stored procedure

  9. 9

    How can I get the name of a variable type, when it's stored as String or Boolean?

  10. 10

    Get variable value by its name stored in another variable in powershell

  11. 11

    Selecting an object property by a name stored in a variable

  12. 12

    Stored procedure with @variable server name

  13. 13

    How to get XAML element by name stored in a string variable?

  14. 14

    Create a variable having name stored in a string variable

  15. 15

    Join with a table name stored in a variable in Rails 3.2

  16. 16

    How to get tag value from input XML where tag name is stored in a variable

  17. 17

    CallerInfo, get name of variable passed to method (like nameof)

  18. 18

    Calling a method (stored in a variable) in a closure

  19. 19

    Python: call a method with the name stored in a variable

  20. 20

    R: How to use $ when the name is stored in a variable?

  21. 21

    Get object dynamically with the name stored in a variable

  22. 22

    R : name of an object stored in a variable

  23. 23

    Get variable by its name, which is stored in another variable

  24. 24

    Separate $_GET information that is stored in a variable?

  25. 25

    javascript call a method with a name stored onto a variable

  26. 26

    Javascript - variable for method name?

  27. 27

    batch Get value of variable stored inside variable

  28. 28

    PostgreSQL Call a stored procedure with its name is into variable

  29. 29

    How to get the return value from an async method, stored in a Task variable

HotTag

Archive