I'm new in javascript, and found some issue with scope of the object/variable, I need your help to point out why my {endtoken:this.token} is blank, while console.log({rawToken:e.data}) is don't?
I found that understanding the scope of the variable bit confusing in JS compared to Python, Is there any good easy to read link to understand the concept?
My goal is to get all data from windows parent and Rest API when the component is created.
var obj = {
token: '',
init: {},
user: {},
objInfo: {}
};
var app = new Vue({
el: '#app-4',
data: obj,
created: function(){
postRobot
.send(window.parent, "loadingCall", false, {domain: domain})
.catch(function (e) {
console.log(e);
});
postRobot
.send(window.parent, "tokenCall", {}, { domain: domain })
.then(function (e) {
this.token = e.data; // token
console.log({rawToken:e.data});
console.log({token:this.token});
})
.catch(function (e) {
console.log(e);
});
postRobot
.send(window.parent, "initCall", {}, { domain: domain })
.then((e)=>{
this.init = e.data;
console.log({rawInit:e.data});
console.log({init:this.init});
})
.catch((e)=>{
console.log(e.data);
});
console.log({endtoken:this.token}); // blank token
console.log({endinit:this.init}); // blank object
}
});
Regards,
Harris, 10th Grade GPS Jakarta