【发布时间】:2015-07-29 20:46:59
【问题描述】:
我有两个简单闭包的例子,我的问题是我什么时候应该返回带或不带括号的函数?谢谢!
示例 1:
function names (first, last) {
var intro = "My name is ";
function full_Name () {
return intro + first + " " + last;
}
return full_Name(); <----
}
full_Name("Macro","phages"); // My name is Macro phages
示例 2:
function names (first) {
var intro = "My name is ";
function full_Name (last) {
return intro + first + " " + last;
}
return full_Name; <---- why not full_Name();
}
var white_cells = names("Macro");
white_cells("phages"); // My name is Macro phages
【问题讨论】:
标签: javascript