网络编程 
首页 > 网络编程 > 浏览文章

javascript createAdder函数功能与使用说明

(编辑:jimmy 日期: 2025/5/11 浏览:3 次 )
英文原文
createAdder(x) is a function that returns a function. In JavaScript, functions are first-class objects: they can be passed to other functions as arguments and returned from functions as well. In this case, the function returned is itself a function that takes an argument and adds something to it.

Here"codetitle">复制代码 代码如下:
function createAdder(x) {
return function(y) {
return y + x;
}
}
addThree = createAdder(3);
addFour = createAdder(4);
document.write('10 + 3 is ' + addThree(10) + '<BR>');
document.write('10 + 4 is ' + addFour(10));
document.write('-10 + 4 is ' + addFour(-10));


演示代码:

[Ctrl+A 全选 注:引入外部Js需再刷新一下页面才能执行]
上一篇:JavaScript 异步方法队列链实现代码分析
下一篇:js 全兼容可高亮二级缓冲折叠菜单
一句话新闻
Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 网站地图 SiteMap