我想创建一个将在另一个函数中调用的匿名函数。我试过这个,为什么它不起作用
function parent (i){
retrun function () {
console.log(i)
}
}
var anonym = parent(2);
function callback (fn){
fn();
}
callback(anonym);
答案 0 :(得分:2)
您的退货声明中存在拼写错误。请检查返回拼写,
function parent (i){
return function () {
console.log(i)
}
}
var anonym = parent(2);
function callback (fn){
fn();
}
callback(anonym);
答案 1 :(得分:1)
function parent(i) {
function callback(fn);
alert("The function called 'function parent' has been called.");
}
function callback(fn) {
alert("The function called 'function callback' has been called.");
}