javascript - JS 使用 onSuccess() 语法
问题描述
我有一些代码,我只是看到语法有问题。
这是代码:
async mymethod(onSuccess, onFailure) {
try {
// Do some here
onSuccess()
}
catch (e) {
//this was an error
}
}
我想做的就是onSuccess()
我想做的事情。
试过:
onSuccess((function() {
// Do something
}))
但似乎存在语法错误。
我如何使用onSuccess()
它并用它做些什么?
解决方案
您缺少function
关键字:
async function mymethod(onSuccess, onFailure) {
try {
// Do some here
onSuccess()
}
catch (e) {
//this was an error
onFailure()
}
}
mymethod(() => alert('success'), () => alert('failure'));
推荐阅读
- r - 在矩阵的每一列中随机将除一个 1 之外的所有内容更改为 0 的快速例程
- sql - 初学者 SQL 问题,试图搜索属于同一组的用户
- python - 类型错误:'在
' 需要字符串作为左操作数,而不是 dict_keys - c# - 将 RichTextBox 的 SelectionChanged 事件和组合框的 TextChanged 事件用于 FontSize 会引发 DependencyProperty.UnsetValue 错误
- postgresql - 使用 Sequelize 动态获取数据库 URL
- html - 响应式媒体查询 div 元素未将元素向左对齐
- javascript - 使用来自 https://maps.googleapis.com/maps/api/place/ 的图片
- html - 反应没有附加事件侦听器
- haproxy - 替换 HAproxy 2.x 的 regrep
- javascript - 机器人不使用 !play 命令播放声音