0

This is a simplified example, but the goal is to have a function that returns a function given a set of arguments, and the returned function should have those arguments expanded into numbers/strings.

The example here returns a function that checks whether a set of coordinates are within a rectangle:

function createFunction(startX, startY, width, height) {
    return function(x, y) {
        if (x >= startX && x <= startX+width && y >= startY && y <= startY+height) {
            return true;
        }
        return false;
    };
}

var myFunction = createFunction(5, 10, 200, 100);

console.log(myFunction); //startX and the other arguments aren't expanded

The problem described in the comment above is that the arguments from the "createFunction" function aren't expanded into values, and if one used the returned function it would create an error because startX and the other arguments aren't globally defined.

How do I return a function with the variables expanded?

Tom Burris
  • 380
  • 2
  • 19

0 Answers0