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);
}