我存储在我的数据库的功能,并从与的node.js意外令牌)节点JS的eval一个functtion
数据库中检索它,当我console.log
包含该函数是这样的输出
(function(settings){var options = {host: 'somehost.com',path: 'some/path/' + settings.token + '?mobile=' + settings.number + '&message=' + settings.message};callback = (function(response) {var str = '';response.on('data', (function (chunk) {str += chunk;}));response.on('end', (function() {settings.result(str);})));}settings.httpRequest.request(options, callback).end();})
列
当我console.log
typeof
列它打印出string
但是当我做
var func = eval(column);
结果Unexpected token)
有谁知道为什么?
我已经作出了更小的功能现在:
function(settings){var options = {host: 'api.smsmonster.co.za',path: '/uv1.svc/SendSMS/' + settings.token + '?mobile=' + settings.number + '&message=' + settings.message}settings.httpRequest.request(options, settings.callback).end();}
忘了一点尝试去掉括号围绕函数声明。 – 2013-02-28 15:18:50