【ES5 ES6】使用学习
转载:
=============================================================
1、Promise
=============================================================
1、Promise
基本使用
const promise = new Promise(function (resolve, reject) { console.log('pending ...'); let random = parseInt(Math.random() * 10); let response = random % 2 == 0 ? true : false; if (response) { resolve(response); } else { reject(response); } }); promise.then(response => { console.log('success: ' + response); }, error => { console.log('failure: ' + error); });