npm install magic-object
const MagicObject = require('magic-object');
const magicObject = new MagicObject((path, args) => {
return {path, args};
});
console.log(magicObject.foo.bar(1)); // output: {path: ['foo', 'bar'], args: [1]}
const magicObject = new MagicObject(async (path, args) => {
return {path, args};
});
console.log(await magicObject.foo.bar(1)); // output: {path: ['foo', 'bar'], args: [1]}