I'm new to javascript and I have a question: I'm trying to extend a function that takes a parameter and that same parameter is present in the methods of the object it returns. However, I would like to know if it's possible to have a second function that returns an object that extends the first function and those parameters are accessible in the second function.
const provider = (firstName) => (
{
lastName: "Doe",
id: 5566,
method: function() {
return firstName + " " + this.lastName;
}
});
const extender = (prov, )=> ({
...prov,
method_2: function (){
return firstName + " " + this.lastName;
}
});
console.log(provider("John").method())
ext_inst = extender(provider("John"))
console.log(ext_inst.method())
//console.log(ext_inst.method_2())