javascript - Binding values to variables mentioned in a script -
i'm creating gwt version of java library has support javax.script.scriptengine evaluate functions dynamically via javascript, e.g.,
o => o % 2 == 0
where @ runtime, value of "o" defined via javax.script.bindings (the o =>
part stripped of course).
the problem is, how can same effect within gwt? use native function
native object nativeeval(string script) /*-{ return $wnd.eval(script); }-*/ nativeeval("o % 2 == 0");
but how can bind value identifier "o"?
new function("o", "return (" + expressionthatuseso + ")")(o)
if expressionthatuseso
"o % 2"
equivalent global function called
(function (o) { return o % 2; })(o)
for reference, https://developer.mozilla.org/en/javascript/reference/global_objects/function :
new function ([arg1[, arg2[, ... argn]],] functionbody)
parameters
arg1, arg2, ... argn
names used function formal argument names. each must string corresponds valid javascript identifier or list of such strings separated comma; example
"x"
,"thevalue"
, or"a,b"
.
functionbody
a string containing javascript statements comprising function definition.
Comments
Post a Comment