为什么程序退出主循环?

时间:2015-12-07 14:41:07

标签: javascript node.js

我有以下代码传递问题的本质:

var body = "";
for(var i=0; i<=5000; i++) {
  body += "if(str==='value" + i + "') 1==1;\n";
}
body += "return str;";

var f1 = new Function("str", body);
var f2 = new Function("str", body);

console.log(f1('test1'));
console.log(f2('test2'));

// main loop
for(var i=0; i<100000; i++) {
  f1("string");
  f2("string");
  console.log(i);
}

console.log("fin!");

为什么主循环周期在结束前不起作用,并且程序退出(因此不显示错误信息)?

PS line&#34; fin!&#34;将不会显示。

我的nodejs版本是5.0.0

我的实际输出:

test1
test2
1
2
3
.
.
~1971

1 个答案:

答案 0 :(得分:-1)

试试这个:

var i = 0;    
for(i=0; i < 5001; i++) {
      body += "if(str==='value" + i + "') 1==1;\n";
    }

但我认为这些功能有问题......