Ruby's Louvre

每天学习一点点算法

导航

2012年2月15日 #

javascript题目,重写函数让其无限相加

摘要: 群里有个出了一道有趣的题目,分享出来让大家看看。function add(x) {________}; alert(add(2)(3)(4)); //填空,使结果为9解法一,//貘大function add(x) { var c = 0; return function(x) { c = c + x ; arguments.callee.toString = function(){ return c; }; return arguments.callee; }(x);}; alert(add(2)(3)(4)... 阅读全文

posted @ 2012-02-15 10:19 司徒正美 阅读(5372) 评论(20) 推荐(1) 编辑