I have a miss understanding, is the strainer function an example the downward funarg problem? I was using the chrome debugger under the sources panel and noticed this under the scope section.
Is the strainer function param cb
a closure or is the function strainer
the closure? I'm finding it difficult to sort through the information about closures and the funarg problem on the web. I clearly don't understand the funarg problem or closures and need some help?
function strainer(collection, cb) {
return collection.reduce(function inner(acc, curr) {
if (cb(curr)) {
return acc.concat(curr);
}
return acc;
}, []);
}
function even(number) {
if (number % 2 === 0) {
return true;
}
return false;
}
var collection = [1, 2, 3, 4, 5];
strainer(collection, even);
Background: I was under the impression private variables returned to an outer environment created closures but the example looks like something different.
The flintstones function example below has closure over the scope of the quotes function.(I think this is the upward funarg problem)
function quotes() {
var x = 'yabba dabba doo!';
return function flintstones() {
return x;
}
}
var fredSays = quotes();
fredSays();