为了账号安全,请及时绑定邮箱和手机立即绑定

急求!!!!js promise 封装异步方法

急求!!!!js promise 封装异步方法

慕妹3242003 2019-08-17 10:36:22
constfoo=str=>{constlen=str.lengthsetTimeout(()=>{bar({str,len})},len*Math.random())}constbarz=string=>newPromise(resolve=>{//代码开始foo(string)global.bar=//该怎么写//代码结束})barz('12345').then(o=>console.log(o.len))//5barz('123').then(o=>console.log(o.len))//3barz('123456').then(o=>console.log(o.len))//6已知foo方法,输入字符串,一段时间后会调用bar方法现在要写一个barz方法,把foo封装成一个promise对应的输入有对应的返回,但是代码该如何写呢?如何用promise的方式正确handle对应的bar?
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 308 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号