有人可以帮我理解如何调用这个JS函数表达式
var math = {
'factorial': function factorial(n) {
if (n <= 1)
return 1;
return n * factorial(n - 1);
}
};
答案 0 :(得分:1)
你走了。应该是不言而喻的:
var math =
{
'factorial': function factorial(n)
{
if (n <= 1)
return 1;
return n * factorial(n - 1);
}
};
var result = math.factorial(3);
// For the purposes of illustration, we will use document.write to output
// the result. document.write is generally not a good idea, however!
document.write(result);