js callback , ajax call back can observer mvvm

来源:互联网 发布:淘宝主图背景图片大全 编辑:程序博客网 时间:2024/06/06 19:42

Refer : http://www.jb51.net/article/59447.htm

  do something other  || like android network after the net work down  do some thing    by param but android only can pass the param by interface callBack  just like click event  android -- web    {        class Demo{            network(fun){                        setTimeout(()=>{                            fun.call(this);                        },3000)                  }        }    new Demo().network(()=>{            alert(1);      })    }

带参数的也比较简单

  do something other  || like android network after the net work down  do some thing    by param but android only can pass the param by interface callBack  just like click event  android -- web    {        class Demo{            network(fun){                        setTimeout(()=>{                            // use obj where in call the function and pass param                             fun.call(this,"d");                        },3000)                  }        }    // todo:// --> you can get the return value by this way    new Demo().network((e)=>{            alert(e);      })    }
   var _$ = function (id) {    this.ele = document.getElementById(id);   }    // the prototype method need after new   _$.prototype = {       dod:function () {         alert(1);       },       bind:function (eve,callback) {           this.ele.addEventListener(eve,()=>{               callback.call(this,this.getX());           });       },       getX:function (e) {           let eve = e||window.event;           if(eve.pageX) {               return 1;           }else{               return 0;           }       }   }   //why not rename   window.$=function(id)   {       return  new _$(id);   }
0 0
原创粉丝点击