当评估_.template并发生ReferenceError时,节点JS FREEZES

时间:2016-07-26 21:19:24

标签: javascript node.js underscore.js

我在Node JS中找到了http://underscorejs.org/的奇怪行为:

当我们评估模板函数时发生引用错误时,Node JS将FREEZE!

示例:

示例1:HAPPY DAY SCENARIO:

var template = "<%= test %>";
var compiledTemplate = _.template(template);
var result = compiledTemplate({test:1});
console.log(result);

//RESULT (both BROWSER and NODE JS):
//1

示例2:COMPILE ERROR SCENARIO(额外=关闭前):

var template = "<%= test =%>";
var compiledTemplate = _.template(template);
var result = compiledTemplate({test:1});
console.log(result);

//RESULT (both BROWSER and NODE JS):
//uncaughtException { [SyntaxError: Unexpected token )]

示例3:评估错误情景(测试未定义):

var template = "<%= test %>";
var compiledTemplate = _.template(template);
var result = compiledTemplate({no_test_defined:1});
console.log(result);

//RESULT (BROWSER):
//Uncaught ReferenceError: test is not defined
//RESULT (NODE JS):
//Node JS FREEZES - nothing happens, neither and error is thrown, neither the flow goes on

有人曾经有类似的行为吗?解决方案的任何提示?我真的需要在try / catch块中捕获异常......

干杯!

的奥斯卡

1 个答案:

答案 0 :(得分:-1)

经过一些故障排除后,我终于找到了问题所在。

当我在Webstorm DEBUGGER中运行时,会发生这种行为(Node JS FREEZES)。当我在命令行中运行它时,我按预期工作。如果他们有什么东西,我会搜索Webstorm问题。

干杯!!!!

的奥斯卡