A clever use of JavaScript functions: Assuming that the action has a Jsonobject type of object data, its value may be empty, the foreground JSP page in the JS code would like to directly through the El expression, that is, the form of ${data} to access the value of the object, May cause JS preprocessing error because the data object is empty, such as the JSP has such code, VAR obj=${data}, when the background data is null, the foreground page will become Var obj=, and the page error is terminated. Some people want to solve the problem by a similar var obj= (' ${data} ' = = ' {}:${data}), but the code is still compiled, because the preprocessing becomes var obj= (' = = '? {}:), direct syntax error, this situation is generally only through ' ${data} ' Give this value to a string and then convert it to a JSON object through the eval () function or the introduction of a third-party JSON library, which can also be resolved by the following function:
function Getjsondata (data) {
if (arguments.length>0) {
return data;
}
return {}
}
var obj = Getjsondata (${data});
2015 37th Friday JavaScript function arguments object skillfully with a