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

推荐订阅源

MyScale Blog
MyScale Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
罗磊的独立博客
博客园 - 叶小钗
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
美团技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
雷峰网
雷峰网
宝玉的分享
宝玉的分享
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
爱范儿
爱范儿
小众软件
小众软件
K
Kaspersky official blog
P
Proofpoint News Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - Franky
V
Vulnerabilities – Threatpost
博客园_首页
Microsoft Security Blog
Microsoft Security Blog
C
Cybersecurity and Infrastructure Security Agency CISA
V
V2EX
C
Check Point Blog
S
Schneier on Security
P
Palo Alto Networks Blog
IT之家
IT之家
GbyAI
GbyAI
T
Threat Research - Cisco Blogs
Hugging Face - Blog
Hugging Face - Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Apple Machine Learning Research
Apple Machine Learning Research
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tailwind CSS Blog
Project Zero
Project Zero
Y
Y Combinator Blog
V
Visual Studio Blog
Simon Willison's Weblog
Simon Willison's Weblog
T
Threatpost
Scott Helme
Scott Helme
L
LINUX DO - 热门话题
S
Securelist
C
CERT Recently Published Vulnerability Notes
A
Arctic Wolf
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理

博客园 - Young.Jiang

Iframe的高级操作 设计模式学习:适配器模式 Linq学习笔记(2.3)——DLinq高级操作 Linq学习笔记(2.2)——深入DLinq查询 Linq学习笔记(2.1)——初识 DLinq Linq学习笔记(1.8)——Count、Sum、Min、Max、Average Linq学习笔记(1.7)——First、ElementAt、Any、all Linq学习笔记(1.6)——ToArray、ToList、ToDictionary、OfType Linq学习笔记(1.5)——group、Distinct、Union、Concat、Intersect、Except Linq学习笔记(1.4)——orderby、Reverse() Linq学习笔记(1.3)——Take、Skip Linq学习笔记(1.2)——select Linq学习笔记(1.1)——where 理解JavaScript中的对象 Asp.net Ajax 客户端编程(二)——Type 类,面向对象编程的开始 Asp.net Ajax 客户端编程(一)——对JS基本类型的扩展 提高.NET性能的最佳实践 EnterpriseLibrary 3.0的缓存应用程序块 EnterpriseLibrary 3.0的验证应用程序块
Javascript模拟c#方法重载
Young.Jiang · 2008-12-09 · via 博客园 - Young.Jiang

每次看John Resig的blog,都会有很大的收获!这次和大家一起分享一个Javascript模拟c#方法重载的例子。

 function loadMethod(object, name, fn){ 
            
var old = object[ name ]; 
            
if ( old ) 
                object[ name ] 
= function(){ 
                    
if ( fn.length == arguments.length ) 
                        
return fn.apply( this, arguments ); 
                    
else if ( typeof old == 'function' ) 
                        
return old.apply( this, arguments ); 
                }; 
            
else 
                object[ name ] 
= fn; 
        }

下面写一个在用户集合中查找特定用户数量的例子

function UserCount(){ 
            loadMethod(
this"find"function(list){ 
                
//查找所有数量
                var i=0;
                
return list.length;
            }); 
            loadMethod(
this"find"function(list,pwd){ 
                
//查找特定密码的用户数量
                var k=0;
                
for(var i=0;i<list.length;i++)
                {
                    
if(list[i].pwd==pwd)
                        k
++;
                }
                
return k;
            }); 
            loadMethod(
this"find"function(list,id, pwd){
                
//查找特定密码和id的用户数量 
                var k=0;
                
for(var i=0;i<list.length;i++)
                {
                    
if(list[i].id==id && list[i].pwd==pwd)
                        k
++;
                }
                
return k;
            })
        }

//定义集合
        var userlist=new Array();
        userlist.push({id:
"holygrace",pwd:"12345"});
        userlist.push({id:
"JiangYuYang",pwd:"2233"});
        userlist.push({id:
"liyanhong",pwd:"12345"});
        userlist.push({id:
"mayun",pwd:"adf"});
        userlist.push({id:
"wangzidong",pwd:"3456"});
        
        
var count=new UserCount()
        alert(
"find(userlist)找到\n"+count.find(userlist)+"");
        alert(
"find(userlist,\"12345\")找到\n"+count.find(userlist,"12345")+"");
        alert(
"find(userlist,\"holygrace\",\"12345\")找到\n"+count.find(userlist,"holygrace","12345")+"");