A javascript Loading Picture Problem

  node.js, question

An example of asynchronous loading of pictures can be seen on Elevation III and some blogs.

Callback function version:
 function loadImage(url,cb){
 var img = new Image();
 img.onload=function(){
 cb(img);
 bracket
 img.src=url;
 bracket
 
 Promise version:
 function loadAsyncImage=function(url){
 return new Promise(resolve,reject){
 var image = new Image();
 image.onload = () =>{
 resolve(image);
 };
 image.onerror = () =>{
 Reject (newerror ('couldnot loadimageat' plus url));
 };
 image.src=url;
 bracket

bracket
I would like to know why img.src=url should be written at the end, can it be written before the code that binds callback function for picture object?

If I remember correctly, img will start downloading as long as the src attribute is set, while script, which requires adding src attribute and adding it to the document, will start downloading. in some cases, if the src of img is set in advance, and the event binding is late, or the picture is loaded in advance, the corresponding event may not be triggered. generally, there should not be too much difference, but this writing is more in line with the processing order. page 364 of the third edition of “JavaScript advanced programming” has said this problem