Use apply to wrap variadic functions. id1(f) returns a function that works just like f (if f doesn't use this), but only when it's called with one argument. id2(f) works just like f, but only when it's called with two arguments. idn works with any number of arguments.

Results

function id1(fn) {
    return function(x) {
        return fn(x);
    }
}
 
function id2(fn) {
    return function(x, y) {
        return fn(x, y);
    }
}
 
function idn(fn) {
    return function() {
        return fn.apply(this, arguments);
    }
}