|
|
|
|
|
by kylec
4908 days ago
|
|
Using closures to encapsulate private variables is a good idea, but the way this article recommends doing it doesn't demonstrate any of the benefit as it doesn't really close over anything. I don't know if it's an example of good JS code, but something like the basic closure definition of a counter might have better demonstrated the ability to hide state: var counter = (function () {
var i = 0;
return function () {
i += 1;
return i;
}
}());
Where the internal variable, i, is inaccessible to anything but the counter function itself. |
|