I'm trying to return the name of the element inside of the object. Second element is function getBook()
that should return the name of the book but I'm getting undefined
in my console. I have defined the second variable get name that is referencing to the function inside of the object. I'm not sure if I can use return this.element. If anyone can explain why my code is failing I would appreciate that. Thank you.
var books = {
name: 'Goodnight Moon',
getBook() {
return this.name;
}
};
var getName = books.getBook;
console.log(getName());