granmirupa granmirupa - 5 months ago 9
Javascript Question

JavaScript: How can I get code as String?

I have this object:

{ tag: 'button',
attrs: { onClick: this.myFunc },
children: 'Name' }


This object is in a context where
this.myFunc
is a function.
How can I get
this.myFunc
?

If I try with:
obj['attrs']['onClick']
it prints all of the function:

function(event){...}

Answer

Have you tried this to get the function name as a string

obj.attrs.onClick.name;

This would most likely return "myFunc" and not "this.myFunc" though, just depends what you want.