我正在学习JavaScript,我不太明白什么时候写一个函数到变量中。什么时候应该将函数存储到变量中?
例如,以下两个代码块的做同样的事情的Node.js:
var onReq = function(req, res) {
res.write('Hello');
};
http.createServer(onReq).listen(3000);
和
function onReq(req, res) {
res.write('Hello');
}
http.createServer(onReq).listen(3000);
这是根据最好做的最好的方法做法,为什么?
对于这个问题,你需要对字符串变量和整数更加集中和浮点变量; – 2012-03-08 13:47:29
http://stackoverflow.com/questions/1013385/what-is-the-difference-between-a-function-expression-vs-declaration-in-javascrip – jbabey 2012-03-08 14:06:23
重复:http://stackoverflow.com/questions/336859/JavaScript的VAR-functionname功能-VS-功能functionname – 2012-03-08 14:12:52