Answer the question
In order to leave comments, you need to log in
How to get the result of a javascript function?
Hello!
I'm dumb and can't figure it out.
Let's say I have a function (from Open Api VK):
VK.Auth.getLoginStatus(function(response) {
if (response.session) {
/* Авторизованный в Open API пользователь */
} else {
/* Неавторизованный в Open API пользователь */
}
});
. Answer the question
In order to leave comments, you need to log in
If the function is executed synchronously, then you can simply insert return true;
or inside the conditions return false;
. For example:
function calc (a, b) {
return a + b;
}
var result = calc(2, 2);
console.log(result) // 4
var auth;
VK.Auth.getLoginStatus(function(response) {
if (response.session) {
/* Авторизованный в Open API пользователь */
auth = true;
next();
} else {
/* Неавторизованный в Open API пользователь */
auth = false;
next();
}
});
// продолжаем работу
function next () {
//...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question