"A decorator is just an expression that will be evaluated and has to return a function." It seems to me that it's just sugar for wrapping functions... is there some reason that couldn't be optimized?
Unfortunately, due to hoisting decorating top-level functions is a real pain [1].
What should the behavior of:
myMagicFunction();
var myDecorator = require('myDecorator');
@myDecorator
function myMagicFunction() {
// TODO: Make magic
}
be?
- `myDecorator`'s require statement is hoisted above `myMagicFunction`'s declaration so that `myMagicFunction` is always decorated? (Results in a given `var`'s behavior changing depending on whether it is invoked as a decorator, an exceedingly non-obvious behavior)
- Function hoisting doesn't happen for decorated functions (non-obvious, possibly hard to implement).
- Function hoisting happens but the decorator is not hoisted (resulting in a sometimes-decorated function).
These problems don't admit of a simple solution (at least as far as I can see).
8 comments
[ 3.2 ms ] story [ 25.4 ms ] threadES Next doesn't exist.
This:
Is equivalent to this:What should the behavior of:
be?- `myDecorator`'s require statement is hoisted above `myMagicFunction`'s declaration so that `myMagicFunction` is always decorated? (Results in a given `var`'s behavior changing depending on whether it is invoked as a decorator, an exceedingly non-obvious behavior)
- Function hoisting doesn't happen for decorated functions (non-obvious, possibly hard to implement).
- Function hoisting happens but the decorator is not hoisted (resulting in a sometimes-decorated function).
These problems don't admit of a simple solution (at least as far as I can see).