Search code examples
javascriptobjectthisobject-literal

when I want to access fullname within the greet method, I get : TypeError: this.getFullName is not a function , how can I fix this ? thanks in advance


let greetings = {
    fullName : "elham zeinodini",
    getFullName : () => {
        return this.fullName;
    },
    Greet : message => console.log(`${message} ${this.getFullName()} !!`)
}



console.log(greetings.fullName);

greetings.Greet("Hello");

Solution

  • let greetings = {
        fullName : "elham zeinodini",
        getFullName() {
            return this.fullName;
        },
        Greet(message) {
          console.log(`${message} ${this.getFullName()} !!`)
        }
    }
    console.log(greetings.fullName);
    greetings.Greet("Hello");