function _fetch(callback){
const xhr = new XMLHttpRequest()
xhr.onReadyStateChange = ()=> {
if(xhr.readyState = xhr.Done && xhr.status == 200 ){
callback(xhr.responseText)
}
}
xhr.open('GET','http://localhost:8899')
xhr.send()
}
let data;
_fetch((res)=>{
data = res.data;
})
function _fetch(){
return new Promise((resolve,reject) => {
const xhr = new XMLHttpRequest()
xhr.onReadyStateChange = ()=> {
if(xhr.readyState = xhr.Done && xhr.status == 200 ){
resolve(xhr.responseText)
}
}
xhr.open('GET','http://localhost:8899')
xhr.send()
})
}
let data;
_fetch()
.then((res)=>{
data = res.data
})
function _fetch(){
return new Promise((resolve,reject) => {
const xhr = new XMLHttpRequest()
xhr.onReadyStateChange = ()=> {
if(xhr.readyState = xhr.Done && xhr.status == 200 ){
resolve(xhr.responseText)
}
}
xhr.open('GET','http://localhost:8899')
xhr.send()
})
}
co(function *(){
let data = yield _fetch()
console.log(data)
})
function _fetch(){
return new Promise((resolve,reject) => {
const xhr = new XMLHttpRequest()
xhr.onReadyStateChange = ()=> {
if(xhr.readyState = xhr.Done && xhr.status == 200 ){
resolve(xhr.responseText)
}
}
xhr.open('GET','http://localhost:8899')
xhr.send()
})
}
(async () => {
let data = await _fetch()
console.log(data)
})()