JavaScript Patterns 4.3 Returning Functions

it2022-05-05  113

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); }; }; // usage var next = setup(); next(); // returns 1 next(); // 2 next(); // 3

转载于:https://www.cnblogs.com/haokaibo/p/Returning-Functions.html


最新回复(0)