When I managed to define a function inside prototype object, but when I use foreach loop on the props I found this method as one of my props either.
I wanted to know if I can define methods like the toString() mehtod?
the hasOwnProperty() if inside the loop is not an option for me because the loop is inside a package.
Here is my code.
function Person (personProps) {
Object.assign(this, {...personProps});
console.log(this);
}
Person.prototype.sayHay = () => {
console.log("hay");
}
const createPerson = (personProps) => {
let x = new Person(personProps);
x.sayHay();
return x;
};
export default createPerson;
Thanks for helping.