cc = (resolve, reject) => { const timeOut = 5 setTimeout(function () { if (timeOut < 1) { console.log('call resolve()...'); resolve('200 OK'); } else { console.log('call reject()...'); reject('timeout in ' + timeOut + ' seconds.'); } }, timeOut * 1000); } clickFunction = () => { new Promise(this.cc).then(data => { alert(data) }).catch(function (reason) { console.log('Failed: ' + reason); }); }
<button onClick={this.test}>a</button>