If a non-constructable value is returned, then an error is thrown?
trusktr opened this issue · 5 comments
trusktr commented
Does this mean decorators can still return plain function
s? f.e.
function log(Class) {
return function () {
console.log('instantiating class')
return new Class()
}
}
@log
class Foo {}
new Foo() // logs "instantiating class"
?
Or does it have to be a class
?
pzuraq commented
Class decorators must return a callable value, it does not need to be constructable, per the spec: https://arai-a.github.io/ecma262-compare/?pr=2417&id=sec-applydecoratorstoclassdefinition
trusktr commented
Oh ok. So then any function is ok to return, not just anything callable with new
? If so, the README could use an update.
pzuraq commented
Yes, and proxies are also ok to return, as they can intercept calls.