promise 应用实例

1、图片的加载

function loadImageAsync(url){
    return new Promise(function(resolve,reject){
        const image = new Image();
        
        image.onload = function(){
            resolve(image);
        };
        
        image.onerror = function(){
            reject(new Error('Can not load image at'+url));
        }
    
        image.src = url;
    });
}

 

posted on 2018-02-23 14:25  taoshengyijiuai  阅读(237)  评论(0编辑  收藏  举报