js callback , ajax call back can observer mvvm

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);
   }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值