I have a function from an object, lets say Object.MyFunc. I need to send this function name into another function like so: doSomething("Object.MyFunc");
any advise?
Code to Convert a Function to String To convert a function to string, use the toString() method of a function object.
There are two methods to call a function from string stored in a variable. The first one is by using the window object method and the second one is by using eval() method. The eval() method is older and it is deprecated.
In Python an integer can be converted into a string using the built-in str() function. The str() function takes in any python data type and converts it into a string.
Method 1: Get Function Name in Python using function. func_name. By using a simple function property function, func_name, one can get the name of the function and hence can be quite handy for the Testing purpose and also for documentation at times.
This is an old question, but in ES6 this ability is provided via the Function.name
property. The ECMAScript 2015 Language Specification defines how this property is added to a Function instance:
9.2.11 SetFunctionName (F, name, prefix)
The abstract operation
SetFunctionName
requires aFunction
argumentF
, aString
orSymbol
argumentname
and optionally aString
argument prefix. This operation adds aname
property toF
by performing the following steps: ...
Unfortunately, this hasn't yet been implemented in all major browsers: It's listed here as not supported in all IE versions, and only partially supported in all other major browsers (with Edge 13 having the best, albeit still partial, support currently).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With