gpt4 book ai didi

javascript - 修改函数以调用给定的回调并返回其结果

转载 作者:行者123 更新时间:2023-11-30 06:12:35 26 4
gpt4 key购买 nike

伙计们,这让我难住了!任何帮助都会很棒!我们还没有学过这个,这让我大吃一惊。

function invokeCallback(cb) {
alert (CB)
}

enter code here

/* Do not modify code below this line */

const exampleCallback = function() {
return 'hello';
};

const invokedResult = invokeCallback(exampleCallback);

console.log(invokedResult, '<-- should be "hello"');

最佳答案

要在控制台中打印输出,您不需要警报。只需返回函数 cb()

function invokeCallback(cb) {
return cb();
}

/* Do not modify code below this line */

const exampleCallback = function() {
return 'hello';
};

const invokedResult = invokeCallback(exampleCallback);

console.log(invokedResult);

关于javascript - 修改函数以调用给定的回调并返回其结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58004234/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com