我是一名新的ecmaScript6学生。
我需要在封装库函数时链接到“ then” promise。
Swal是sweetalert2函数,用于询问问题并获得用户的答复,是/否。
这就是我想要做的事
class MyLib {
constructor() {
}
static askQuestion(title,message){
Swal.fire({
title: title,text: message,showCancelButton: true,confirmButtonColor: '#3085d6',cancelButtonColor: '#d33',confirmButtonText: 'Yes,delete it!'
}).then((result) => {
return result;
})
}
}
然后像这样调用该函数;
MyLib.askQuestion("Are you sure?","Are you sure you want to delete this ?").then(alert(result));
当然可以;在运行时控制台上,由于警报(结果),显示“ .askQuestion(...)未定义”。
如何在es6中链接两个然后起作用的函数?