views:

65

answers:

2

hi,

i have a value like that

var myvalue = myfunction(1,2);

what I need is that GETTING myfunction(a,b) as a string..

I mean not "myfunction's value"

hmmm, let me explain,

myfunction(1,2) returns 1+2=3

if I type

alert(myvalue)

it returns 3 but I need myfunction(a,b) AS IT'S TYPED when I use alert. NOT IT'S VALUE

think it like

var myvalue='myfunction(a,b)'

now, if i use Alert, it gives me myfunction(a,b)

how can I do that?

+2  A: 
var myvalue = function()
{
  myfunction(1,2);
};

myvalue is a anonymous function that calls myfunction with the specified parameters. You can call it, and if you print it for debugging, it will look something like:

function () { 
   myfunction(1, 2); 
}
Matthew Flaschen
Matthew, thank you.it works but my value isn't like that.var myvalue = function(){ myfunction(1,2);};I can get this on console.log as its typed--------is it possible to get myvalue if it looks like the following?my value=function(a,b)
darkandcold
If you have the code `myvalue = myfunction(a,b);`, myvalue will always be the return value from myfunction. There's no getting around that.
Matthew Flaschen
A: 

If you want to get the string value of a function, you can use the builtin toString method

var f1 = function(a, b) {
    return a + b;
};

function f2(a, b) {
    return a + b;
};

console.log(f1.toString());
console.log(f2.toString());

yields

function (a, b) {
    return a + b;
}
function f2(a, b) {
    return a + b;
}

But why do you want to do this?

Justin Johnson