开发者

how to get a value which points to a function

开发者 https://www.devze.com 2022-12-30 14:35 出处:网络
i have a value like that var myvalue = myfunction(1,2); what I need is that GETTING myfunction(a,b) as a string..

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(myval开发者_运维知识库ue)

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?


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); 
}


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消