cnick
cnick

Reputation: 332

Display a javascript function as plaintext

I have a javascript object with a defined function

var obj = {
    addOne : function( arg1 ) { return arg1++; }
};

At an onclick event, I want to display the function as plaintext. That is to say I want to somehow get the plaintext string 'function( arg1 ) { return arg1++; }' from obj so that I can display this string in a div block.

How do?

(To be clear, I am fine with printing out the string in an html element, but unclear on how to get the desired string in the first place)

Upvotes: 0

Views: 142

Answers (1)

adeneo
adeneo

Reputation: 318252

var str = obj.addOne.toString();

it's that easy

FIDDLE

Upvotes: 5

Related Questions