Extensible JavaScript function

For the book I am writing, I needed to create a JavaScript function that can tell if a chess move is legal, or not.

Since there are so many ways the pieces can move, this method could potentially be quite messy with lots of nested if-statements, or calls to other functions.

Instead I was wondering if there was a way to extend the existing function with additional rules.

Here is what I came up with:

var Example = Example || {};  
Example.chain = function chain() {  
  var conditions = [];
  var result = function(input) {
    return conditions.every(function(condition) {
      return condition(input);
    });
  };
  result.link = function (condition) {
    conditions.push(condition);
    return result;
  };
  return result;
};

Now we can call the Example.chain function to create the chain.

var chain = Example.chain();  

To add another condition that the function needs to fulfil, we call the link method on the Example.chain function instance. The argument to link is a function that returns true or false, and takes the same kind of input.

var greaterThanOne = function(value) {  
  return value > 1;
};
var lessThanFive = function(value) {  
  return value < 5;
};
chain  
    .link(lessThanFive)
    .link(greaterThanOne);

To evaluate that all the conditions are met, we invoke the result function that was returned when we called the Example.chain function.

console.log("1 < 1 < 5: " + chain(1));  
console.log("1 < 2 < 5: " + chain(2));  
console.log("1 < 5 < 5: " + chain(5));  

The result of the above is:

1 < 1 < 5: false  
1 < 2 < 5: true  
1 < 5 < 5: false