我对JavaScript编程很陌生,并且在理解我在这种情况下如何处理方面没什么帮助:
代码:
var cookieName = 'myCookieName:';
var cookieValue = browser.getcookie('myCookieName', function(response){
console.log(response.value);
return response.value;
});
var cookieString = cookieName + cookieValue;
这就是我打算做的,但cookieValue总是未定义的,但是console.log(response.value) - >打印出正确的值:(
答案 0 :(得分:0)
从回调返回并不意味着调用者函数也将返回相同的值,它不能那样工作-browser.getCookie()将始终返回未定义。
如果您需要使用Cookie的值,则需要在回调函数中进行操作。
var cookieName = 'myCookieName:';
browser.getcookie(cookieName , function(response){
console.log(response.value);
// do what you need to do with the cookie - maybe call another function to process it, for example
processCookieValue(response.value);
});