I have the following code, where I get all the user information from a server:
Promise.all([api.getUserInfo(), api.getCards()])
.then(([userInf, cards]) => {
userInfo.setUserInfo({
name: userInf.name,
job: userInf.about,
id: userInf._id,
});
userInfo.setUserAvatar({
avatar: userInf.avatar,
});
cardsList.renderItems(cards);
})
.catch((err) => console.log(err));
I want to save the userId, (which is above as userInf._id), as a constant outside the function, so I can use it seperately to create cards. But directly writing something like const userId = userInf._id can't be used outside the function. Also trying to create a setUserId and getUserId method like this:
setUserId({ id }) {
this._userID = id;
}
getUserId() {
return this._userID;
}
in the userinfo class does not work since getUserId returns undefined.