Search code examples
javascripttypeerror

Uncaught Typeerror obj2.getName is not a function


const obj = {
    name: "John",
    getName: function() {
        return  this.name
              
    }
}

console.log("Type", typeof(obj.getName())) 

const obj2 = {
    roll: 2,
    desig: "Software developer",
    name : "Peter",
    _proto_: obj 

}
console.log(obj2.getName())

Solution

  • __proto__ with two underscores on each side, not one.