gpt4 book ai didi

javascript - 将参数传递给回调

转载 作者:行者123 更新时间:2023-11-28 15:56:27 31 4
gpt4 key购买 nike

在这种特定情况下如何将参数传递给回调函数。

我有一个函数可以通过这样的回调获取对象

function doSomething({ callbackSuccess : myFunction, callbackError : myOtherFunction})

如何将参数传递给 myFunction 或 myOtherFunction?

就像,如果 myOtherFunction 获取这样的 msg 参数

function myOtherFunction(msg) {
alert(msg);
}

提前致谢

最佳答案

就像将它们传递给任何其他函数一样:

function doSomething(callbacks) {
callbacks.callbackSuccess('foo', 'bar');
}

如果您的意思是“在将它们传递到 doSomething 时”传递它们:

doSomething({ callbackSuccess : function () { myFunction('foo'); }, ... });

关于javascript - 将参数传递给回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18615285/

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