Or, in other words, how to make this work:
function foo(){}
//do something that modifies foo as if it was defined with "function foo(a,b,c){};"
console.log(foo.length);
//output: 3
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It is possible, but maybe not very nice:
Example usage:
Output:
(Live demo: Ideone.com, jsFiddle)
lengthDecoratorwraps the supplied function with a function that takes the same amount of parameters as the supplied function. The parameter count can be changed withupdate.C.f.
new Function(...): Dynamically create a new function.fun.apply(...): “Calls a function with a given this value and arguments provided as an array.”