-2
我在節點JS發現了一個怪異的行爲與http://underscorejs.org/:節點JS凍結和的ReferenceError發生
當我們評價一個模板函數的引用錯誤發生,節點JS將凍結!
實例:
實施例1:HAPPY DAY情景:
var template = "<%= test %>";
var compiledTemplate = _.template(template);
var result = compiledTemplate({test:1});
console.log(result);
//RESULT (both BROWSER and NODE JS):
//1
實施例2:編譯錯誤情形(額外=閉合前):
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塊中發現異常...
乾杯!
奧斯卡