首页 > 网站 > WEB开发 > 正文

JavaScript Patterns 4.3 Returning Functions

2024-04-27 14:22:53
字体:
来源:转载
供稿:网友

javaScript Patterns 4.3 Returning Functions

2014-06-09 22:54 by 小郝(Kaibo Hao), ... 阅读, ... 评论, 收藏, 编辑

Use closure to store some PRivate data, which is accessible by the returned function but not to the outside code.

var setup = function () {    var count = 0;    return function () {            return (count += 1);    };}; // usagevar next = setup();next(); // returns 1next(); // 2next(); // 3

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表