Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code #18

Open
nianxiongdi opened this issue Oct 16, 2019 · 0 comments
Open

code #18

nianxiongdi opened this issue Oct 16, 2019 · 0 comments

Comments

@nianxiongdi
Copy link
Owner

nianxiongdi commented Oct 16, 2019

repeat

function repeat (func, times, wait) {
    return function(){
        var _arguments=arguments;
        var timer = setInterval(function(){
            func.apply(null,Array.prototype.slice.call(_arguments,0));
            --times || clearInterval(timer);
        }, wait);
    }
}

var repeatedFun = repeat(console.log, 10, 100);
repeatedFun("hellworld");



function repeat (func, times, wait) {
    return function(){
        var _arguments=arguments;
        var that=this;
        this.timer=function(_t){
            _t&&clearTimeout(_t);
            var t=setTimeout(function(){
                func.apply(null,Array.prototype.slice.call(_arguments,0));
                --times && that.timer(t);
            },wait);
        }
        this.timer();
    }
}

接口依次调用

 
有一个url数组
var urls = ['/a', '/b', '/c',...]
要求依次请求这几个url, 要求是 第一个请求完了才发第二个请求,第二个完了才发第三个请求
如此依次。

var url = [];
var count = 0;
function getData(url){
    if(count>=url.length) return;
    count++;
    Promise.resolve(jQuery.get(url[0])).then(function(data){
        console.log(data);
        getData(url.slice(1));
    });
}
 

webpack打包原理

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant