async/await
const loadFile = src => new Promise((rs, rj)=>{ const image = new Image(); image.onload = () => rs(image); image.onerror = rj; image.src = src; }); const isValidImage = image => image.width < 70 && image.height<70; loadFile(url).then(file => { if(isValidImage(file)) doSomething(); else alert('Image is invalid and nobody loves you') })
Обсуждают сегодня