In ES5 syntax, a class Foo with a method bar having a property flag can be defined like:
function Foo() {};
Foo.prototype.bar = function() { console.log('bar invoked'); };
Foo.prototype.bar.flag = true;
I could mix up ES5 and ES6 syntax and do:
class Foo {
bar() {
console.log('bar invoked');
};
};
Foo.prototype.bar.flag = true;
Or using just ES6 syntax do:
class Foo {
bar() {
this.bar.flag = true;
console.log('bar invoked');
};
};
If I have to choose I'd go for second option but I dislike the redundancy in including the name of the method within it's definition. Is there a better way?