// 定义退出递归的条件, // 否则进入无限循环 let a = 0; let test = function testName() { a += 1; if (a == 3) return; testName(); } console.log(test(0)); // undefined testName(); // ReferenceError: testName is not defined // 使用字面量定义具名函数, // 在函数外部无法通过名字调用函数, // 只能通过变量调用函数
JavaScript之使用字面量定义具名函数,且实现递归
关注
打赏