Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON with function value with parameters

i have a very little problem but don't know how to solve it. I need to send a JSON with a function, but with parameters and this is my problem.

Sending a function in JSON is simple:

var jsonVariable = { var1 : 'value1', var2 : 'value2', func: function(){ alert('something'); } };

I need something else, need to pass the func function as parameter with parameters.

Example:

var jsonVariable = { var1 : 'value1', var2 : 'value2', func: funcParam(param1,param2) };
function(parameter1, parameter2){
     alert(parameter1 + parameter2);
}

But this don't work :(

Any help with this will be really appreaciated

like image 479
rdarioduarte Avatar asked Nov 24 '11 14:11

rdarioduarte


People also ask

Can JSON have functions?

In addition, JSON can not contain functions. Any JSON text must contain valid JavaScript expressions. In some browser engines, the U+2028 line separator and U+2029 paragraph separator are allowed in string literals and property keys in JSON, but when using them in JavaScript code will result in SyntaxError.

What is JSON parameter?

The JSON parameters file provides parameters that you can change to modify the functionality of Log Analysis Tool. Using this file provides you full control over the job without JCL re-generation and ISPF interaction. This section provides more detailed information on the JSON parameter file.


1 Answers

It's a bit unclear what you want, but if you want to define a function which accepts parameters, you'll want something like this;

var jsonVariable = { var1 : 'value1', var2 : 'value2', func: function(param1, param2){ alert(param1 + param2); } };
like image 141
Matt Avatar answered Sep 28 '22 04:09

Matt