I'm working on a node module and i would like to keep using es6 classes syntax for style consistency but i found this pattern that I can't reproduce:
const proto = module.exports = function(options) {
man.opts = options || {};
function man(sentence) {
man.say(sentence);
}
man.__proto__ = proto;
man.age = 29;
man.say = function(sentence) {
console.log(sentence);
};
return man;
};
The strange thing of this function is that I can call it as a standard constructor and get a man with his methods and props but I can also call man as a function and get the same result as calling his method "say". Basically man('text') produces the same effect of man.say('text'); How can I recreate this pattern using es6 classes syntax?