I have a factory function, where I am returning a Book Object. When I create an object of the Book and change a field value, this is not reflected in the method of the Object. Any idea why this may be happening?
const Book = (title, author, pages, read) => {
const info = () => {
if (read == true) {
return `${title} by ${author} - ${pages} pages - already read`;
} else {
return `${title} by ${author} - ${pages} pages - not read yet`;
}
}
return { title, author, pages, read, info };
}
I create a Book Object using let book = Book(title, author, pages, read);
And change the value of read by accessing the read field directly.
However, when I change the value of read, this is not reflected in the info method.