Your problem here stems from the definition forawait
...
The operator is await
used to wait.Promise
A property is Image.prototype.onload
not a promise, and you do not assign it. If you want to return the property height
after loading, instead I will create Promise
...
addImageProcess(src){
return new Promise((resolve, reject) => {
let img = new Image()
img.onload = () => resolve(img.height)
img.onerror = reject
img.src = src
})
}
Then you used the following to access this value
tmp.addImageProcess(imageUrl).then(height => {
console.log(height)
})
or if inside a function async
async function logImageHeight(imageUrl) {
console.log('height', await tmp.addImageProcess(imageUrl))
}
Phil source
share