var favoriteColor = \"blue\";
function colorGenerator(color) {
return function () { return color; };
}
var getColor = colorGenerator(favoriteColor);
most time we return funciton, our target is limit variable scope and keep state. so your code should be:
function colorGenerator(color) {
var favoriteColor = color; //here keep state
return function (c) { return c===favoriteColor; };
}
var isorange = colorGenerator("orange"); //because you only call colorGenerator one time, so function isorange keep the state : 'orange'
isorange('black') //here return false
isorange('orange') //here return true