function getData(callback){
setTimeout(function(){
var name ='smileyqp';
callback(name);},1000);}
getData(function(data){
console.log(data); //smileyqp
})
Promise
//写法一
var p= new Promise(function(resolve,reject){
setTimeout(function(){
var name ='smileyqp';
resolve(name);},1000);});
p.then((data)=>{
console.log(data); //smileyqp
})
//写法二:
function getData(resolve,reject){
setTimeout(function(){
var name ='smileyqp';
resolve(name);},1000);}
var p= new Promise(getDate);
p.then((data)=>{
console.log(data); //smileyqp
})