Override the arity of a function
<p>I would like to make a generic function wrapper that (for example) prints the called function and its arguments.</p>

<p>Doing so is easy through the <code>arguments</code> quasi-array and simple calls. For example:</p>

<pre><code>function wrap(target, method) {
    return function() {
        console.log(Array.prototype.slice.call(arguments).join(', '));
        return method.apply(target, arguments);
    }
}
</code></pre>

<p>However, this way of doing of course completely loses the arity of the called function (if you didn't know, one can obtain the arity (number of arguments) of a JavaScript function through its <code>length</code> property).</p>

<p>Is there any way to dynamically create a wrapper function that would copy the arguments of the wrapped function to itself?</p>

<hr>

<p>I've thought about creating a new <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function" rel="nofollow">Function object</a>, but I don't see any way to statically extract the arguments list, since the <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function/arguments" rel="nofollow"><code>arguments</code> property</a> is deprecated.</p>
