I have not been studying JavaScript for a long time and now I'm trying to implement the Decorator pattern:
function wrap(f, before, after){
return function(){
return before + f(arguments) + after;
}
}
What I'm wondering about is that if we replace f(arguments)
to f.apply(this,arguments)
there is no obvious difference in output.
Could you please clarify which case is preferable and why?
UPD:
I suppose I have understood what is the bottleneck :)
If we decorate function with aforementioned code without arguments, everything will be ok. But if we have arguments we will have to enumerate them like arguments[0],arguments[1]
etc. Am I right?