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

推荐订阅源

爱范儿
爱范儿
P
Palo Alto Networks Blog
月光博客
月光博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
InfoQ
aimingoo的专栏
aimingoo的专栏
腾讯CDC
T
Threatpost
D
DataBreaches.Net
Vercel News
Vercel News
F
Fortinet All Blogs
Engineering at Meta
Engineering at Meta
C
Cybersecurity and Infrastructure Security Agency CISA
Forbes - Security
Forbes - Security
U
Unit 42
C
Check Point Blog
Blog — PlanetScale
Blog — PlanetScale
O
OpenAI News
量子位
TaoSecurity Blog
TaoSecurity Blog
Microsoft Azure Blog
Microsoft Azure Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Visual Studio Blog
Recorded Future
Recorded Future
云风的 BLOG
云风的 BLOG
Security Archives - TechRepublic
Security Archives - TechRepublic
The Last Watchdog
The Last Watchdog
S
Security Affairs
Attack and Defense Labs
Attack and Defense Labs
罗磊的独立博客
Stack Overflow Blog
Stack Overflow Blog
Microsoft Security Blog
Microsoft Security Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
小众软件
小众软件
S
SegmentFault 最新的问题
www.infosecurity-magazine.com
www.infosecurity-magazine.com
W
WeLiveSecurity
AI
AI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 聂微东
I
Intezer
Know Your Adversary
Know Your Adversary
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
博客园_首页
NISL@THU
NISL@THU
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO

博客园 - 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-01-22 · via 博客园 - howhy
function addMethod(obj,name,fun){
    const old=obj[name];
    obj[name]=function(...args){
        if(args.length===fun.length){
            return fun.apply(this,args);
        }else if(typeof old==='function'){
            return old.apply(this,args)
        }
    }
}
const obj={}

addMethod(obj,'getuser',()=>console.log('getuser'))
addMethod(obj,'getuser',(name)=>console.log('getuser name'))
obj.getuser()
obj.getuser('aaa')

function methodOverLoad(){
    const result={};
    const overload=function(...args){
        const argsTypes=args.map(item=>typeof item).join("-")
        result[argsTypes].apply(this,args);
    }
    overload.addImpl=function(...args){
        const fun=args.pop();
        if(typeof fun!=='function'){
            return;
        }
        const args1=args.map(item=>typeof item).join("-");
        result[args1]=fun;
        
    }
    return overload;
}
const overload=methodOverLoad()
overload.addImpl('number',(num)=>{console.log('number '+num)});
overload.addImpl('string',(str)=>{console.log('number '+str)});
overload.addImpl('number','string',(num,str)=>{console.log('number '+num+'-----'+str)});
overload(23433);
overload("aabbcc");
overload(5555,'9999')