json - How do I define a javascript function as a variable from a variable -
i'm trying create callback function in response jsonp request in node.
i receive callbackname string, , have object (lets var obj = {a : "b"}) need return following :
callbackname({a : "b"});
i tried concatenating strings - got
"callbackname([object object])";
i tried json.stringify got:
"callbackname({\"a\":\"b"});"
which close - it's stringy. there way want?
update
the code i'm using - in aws lambda function (turns out rather significant!)
context.succeed(request.callback + "(" + json.stringify(obj) + ");");
as mentioned below - lambda expects object in succeed, calls json.stringify on.
any ideas on how proceed?
if understand question, need this:
var obj = {a:"b"}; var callbackname = "callback"; var scope = {}; scope.callback = function(e) { return function() { console.log(e); } } settimeout( scope[callbackname](obj), 1000 );
Comments
Post a Comment