惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
B
Blog RSS Feed
云风的 BLOG
云风的 BLOG
G
Google Developers Blog
Recent Announcements
Recent Announcements
A
About on SuperTechFans
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Google Online Security Blog
Google Online Security Blog
Google DeepMind News
Google DeepMind News
S
Schneier on Security
S
Secure Thoughts
T
The Exploit Database - CXSecurity.com
Martin Fowler
Martin Fowler
P
Proofpoint News Feed
Security Latest
Security Latest
Jina AI
Jina AI
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Recorded Future
Recorded Future
T
Tor Project blog
有赞技术团队
有赞技术团队
H
Hackread – Cybersecurity News, Data Breaches, AI and More
N
News | PayPal Newsroom
博客园 - 三生石上(FineUI控件)
MyScale Blog
MyScale Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
Forbes - Security
Forbes - Security
D
DataBreaches.Net
人人都是产品经理
人人都是产品经理
NISL@THU
NISL@THU
C
Cisco Blogs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Google DeepMind News
Google DeepMind News
Project Zero
Project Zero
IT之家
IT之家
T
Threatpost
Cyberwarzone
Cyberwarzone
O
OpenAI News
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
J
Java Code Geeks
P
Proofpoint News Feed
The Last Watchdog
The Last Watchdog
月光博客
月光博客
Latest news
Latest news
MongoDB | Blog
MongoDB | Blog
Apple Machine Learning Research
Apple Machine Learning Research

博客园 - howhy

html 元素包含关系 this 指向 空对象 Object.keys for ...in Reflect.ownKeys ...区别 逻辑运算符和空值运算符 运算符优先级 js 类型显式转换 js 方法重载 fetch timeout js 任务顺序执行 暂停 js 并发任务 判断两个对象是否相同 js 动态拦截属性 js 通用动画 js groupby js 防抖和节流 实现 instanceof 操作符 js 单例模式 js 数组去重和扁平方法 js 继承方法 js new的过程实现 js deepCopy js '=='的隐性类型转换规则
js 高级函数
howhy · 2026-02-03 · via 博客园 - howhy
function animation(duration,from,to,handler){
    const dis=to-from;
    const speed=dis/duration;
    const startTime=Date.now();
    let value=from;
    handler(value);
    function _run(){
        const now=Date.now();
        const time=now-startTime;
        if(time>=duration){
            value=to;
            return 
        }
        const d=time*speed;
        value=from+d;
        handler(value);
        requestAnimationFrame(_run);
    }
    requestAnimationFrame(_run);
}

function debounce(fun,delay){
    let timerId=null;
    return function(...args){
        timerId && clearTimeout(timerId);
        timerId=setTimeout(()=>{
            fun.apply(this,args)
        },delay)
        
    }
}

function paralleltask(tasks,parallelCount){
    return new Promise(resolve=>{
        if(tasks.length===0){
            resolve();
            return;
        }
        let nextIndex=0;
        let taskFinish=0;
        function _run(){
            const task=tasks[nextIndex];
            nextIndex++;
            task().then(()=>{
                taskFinish++;
                if(nextIndex<tasks.length){
                    _run();
                }else{
                    if(taskFinish===tasks.length){
                        resolve();
                    }
                }
            })
        }
        for(let i=0;i<parallelCount && i<tasks.length;i++){
            _run();
        }
    })
   
}

function groupby(arr,generatekey){
    const newObj={};
    for(let item of arr){
        const key=generatekey(item);
        if(!newObj[key]){
            newObj[key]=[]
        }
        newObj[key].push(item)
    }
    return newObj
}


function parallelRendertask(taskdatas,renderTask){
    if(taskdatas.length===0){
        return;
    }
    let i=0;
    function _run(){
        if(i===taskdatas.length){
            return;
        }
        requestIdleCallback(idle=>{
            while(idle.timeRemaining()>0 && i<taskdatas.length){
                //做相应的渲染任务
                renderTask(taskdatas[i]);
                i++;
            }
            _run;
        })       
    }
    _run();
}

posted @ 2026-02-03 16:58  howhy  阅读(13)  评论()    收藏  举报