3 ms·
If you don't mind setting the function on instances at construct time, you can use ES2016 class properties: class x { a = wrapFunction(function() {})
by quarterto 11y ago
If you don't mind setting the function on instances at construct time, you can use ES2016 class properties:
class x {
a = wrapFunction(function() {})
}
This kind of use case is pretty well covered by ES2016 decorators as well (they're a bit more general as they act on property descriptors, not just values):
class x {
@functionWrapper
a() {}
}
- KenanSulayman 11y agoNeat, thanks! But we're working with the half-baked V8 ES6 support that is far from ES2016, unfortunately. However, it's interesting to see the support coming :-)