You can achieve this kind of result by editing the prototype of the function.
Example:
function foo() {
const something = 'the thing';
return something;
}
const customPrototype = {
greeting: (name) => {
const greetingTemplate = `Hello ${name}`;
return greetingTemplate;
},
randomNumber: () => {
return Math.random();
},
};
// Extending prototype to access our custom prototype functions
Object.assign(foo, customPrototype);
console.log(foo()); // the thing
console.log(foo.greeting('People')); // Hello People
console.log(foo.randomNumber()); // 0.26138311987993545
// Default prototype functions are working as well
console.log(foo.toString()); // [object Function]
EDIT: Thanks to @Bergi for correcting me!