I have a scenario that need to add new methods to an object dynamically.
Basically, this new method will be passed as parameter to a function. Then inside the function i will add this method to the object.
sampleFunction(() => console.log("This is new function"))
function sampleFunction(newMethod) {
var Person = {
first_name: "Marty",
last_name: "Mcfly",
born: 1968,
};
let p = new Person();
// code to add new methods to Person Object here ....
}
Above is the example for the scenario i faced.
Really Appreciated if anyone can help me.
Thanks.