Having the following javascript Promise code:
const loadImage = (src) => new Promise((resolve, reject) => {
const img = new Image();
img.addEventListener(`load`,()=>resolve(img));
img.addEventListener(`error`,(event)=>reject(event));
img.src=src;
});
Why it doesn't work if I use resolve(this)
instead of resolve(img)
?
Probably a silly question but... wanting to understand the reason.
I often use this
as reference inside event listeners and it works without troubles... (I'm quite sure the reason is related to the Promise, yet I didn't get it...)
Thank you for your help