When or who does pass resolve and reject functions to JS promises?
<p>I have begun learning javascript promises. But I just can't understand the concept of promises.
The thing that bothers me most is who is passing the Resolver and Reject function to a promise constructor ?</p>
<p>See this example of Promise:</p>
<pre><code>function getImage(url){
    return new Promise(function(resolve, reject){
        var img = new Image()
        img.onload = function(){
            resolve(url)
        }
        img.onerror = function(){
            reject(url)
        }
        img.src = url
    })
}
</code></pre>
<p>Now who does pass resolve and reject methods, as my understanding of javascript says to me that this script will throw unknown variable errors as resolve and rejects are not defined?</p>
<pre><code>getImage('doggy.jpg').then(function(successurl){
    document.getElementById('doggyplayground').innerHTML = '&lt;img src=&quot;' + successurl + '&quot; /&gt;'
}).catch(function(errorurl){
    console.log('Error loading ' + errorurl)
})
</code></pre>
<p>Now you see a method like the above, the only way these methods(resolve and reject) are passed are via then and catch as used in above method call to getImage.</p>