2014年2月12日

摘要: 实参个数可以用arguments.length 获得,期望的形参个数可以用函数的length属性获得function check(args){ var actual=args.length; var expected=args.callee.length; return actual==expected;}//调用方法function f(a,b,c){ if(check(arguments)){ return a+b+c; }else{ console.log("实参个数和期望的形参个数不相等"); }} 阅读全文
posted @ 2014-02-12 12:26 Young_Junior_Man 阅读(267) 评论(0) 推荐(0) 编辑
摘要: 关于闭包的经典题目:#1 针对以下html代码片段,编写javascript实现点击li时弹出其索引。This is the First oneThis is the Second oneThis is the Third one此文讲的是闭包,当然是用闭包来做,但是还是比较容易犯错,因为搞不清闭包的关系,下面把我自己写的糊涂代码贴出来。 var liCollection=document.getElementsByTagName("li"); function alertIndex(idx){ return function(){ alert(idx);} } for(v 阅读全文
posted @ 2014-02-12 10:07 Young_Junior_Man 阅读(144) 评论(0) 推荐(0) 编辑

导航