使用带有箭头函数的承诺后,如何为方法传递额外的参数?
How to pass in additional parameters for the method after using promises with arrow functions?
我是 Typescript 和箭头函数的新手。尝试在打字稿中编写以下内容,但我对回调后的第二个参数感到困惑 - "true".
FB.getLoginStatus(function(response) {
// this will be called when the roundtrip to Facebook has completed
}, true);
这是我目前的情况。我需要帮助来理解为什么 "true" 的位置不正确。
//Is the user already logged in ?
this.fb.getLoginStatus().then((response: any) => {
//Do something
}, true); //Why is this incorrect?
那你为什么要用? getLoginStatus 方法是否更改?在您的第一个示例中,您将回调传递给 getLoginStatus。
这与您的第一个示例完全相同,只是使用了 lambda。
this.fb.getLoginStatus((response: any) => {
// this will be called when the roundtrip to Facebook has completed
}, true);
这个 api 有两个参数 - 一个回调和一个指示访问服务器而不使用缓存信息的标志。
我肯定会为第二个参数传递 true,因为您可能不想使用缓存的结果来确定登录信息。
回调似乎不是 return Promise 对象,因此您不能在其上使用 'then'。它是一个直接的回调函数,将 return 在将来的某个时间响应(即异步)。
看起来其他人也面临我正在使用的库的这个问题 ionic-native/facebook。我将在 Github 上跟踪以下公开票证。感谢您的帮助。
https://github.com/jeduan/cordova-plugin-facebook4/issues/315
我是 Typescript 和箭头函数的新手。尝试在打字稿中编写以下内容,但我对回调后的第二个参数感到困惑 - "true".
FB.getLoginStatus(function(response) {
// this will be called when the roundtrip to Facebook has completed
}, true);
这是我目前的情况。我需要帮助来理解为什么 "true" 的位置不正确。
//Is the user already logged in ?
this.fb.getLoginStatus().then((response: any) => {
//Do something
}, true); //Why is this incorrect?
那你为什么要用? getLoginStatus 方法是否更改?在您的第一个示例中,您将回调传递给 getLoginStatus。
这与您的第一个示例完全相同,只是使用了 lambda。
this.fb.getLoginStatus((response: any) => {
// this will be called when the roundtrip to Facebook has completed
}, true);
这个 api 有两个参数 - 一个回调和一个指示访问服务器而不使用缓存信息的标志。
我肯定会为第二个参数传递 true,因为您可能不想使用缓存的结果来确定登录信息。
回调似乎不是 return Promise 对象,因此您不能在其上使用 'then'。它是一个直接的回调函数,将 return 在将来的某个时间响应(即异步)。
看起来其他人也面临我正在使用的库的这个问题 ionic-native/facebook。我将在 Github 上跟踪以下公开票证。感谢您的帮助。
https://github.com/jeduan/cordova-plugin-facebook4/issues/315