Tag: global

为什么节点认为这不是一个函数,但JavaScript有时是好的?

我有一个更大的项目,我正在通过我configuration的API网关在AWS中调用Lambda。 在Lambda我试图dynamic调用基于API请求上的查询string参数通过使用以下variables: var functionToCall = event.queryStringParameters.tech; console.log("functionToCall is " + functionToCall); global[functionToCall](event, output); 不幸的是我得到一个错误 TypeError: global[functionToCall] is not a function 我已经重写了这个使用窗口来演示它在线和取决于我是否运行在jsbin或jsfiddle我得到不同的结果。 以下在jsbin中的作品: 'use strict'; var functionArray = ["one", "two", "three"]; var randFunction = functionArray[Math.floor(Math.random() * functionArray.length)]; function one() { console.log("function one called"); }; function two() { console.log("function two called"); }; function three() { console.log("function three […]

NodeJS REPL:为什么这个variables赋值失败?

有人能帮我理解下列行为吗? 我预料到,由于我可以在这个callback中设置全球f ,我也应该能够改变它。 我不明白在REPL中节点如何处理上下文和全局的问题,以便理解这一点,我非常感谢你的支持。 不使用useGlobal启动REPL $ cat test.js var repl = require('repl'); repl.start({useGlobal:false}); 现在尝试连续两次设置f : $ node test.js > f ReferenceError: f is not defined > setTimeout(function(){f=1;}, 0); > f 1 第一次工作…现在再试一次: > setTimeout(function(){f=2;}, 0); > f 1 咦! 第一次运行设置它; 第二个不影响它。 (设置useGlobal : true我得到了我期望的行为。)