vendredi 29 mai 2020

call() is not working with getter and setter in javascript

let Name = {
   get fullname() {
        return this.fname + this.last
    }
}

function pension() {
    return this.age > 60
}
let firstclass_employee = [{
    fname: "sangeth",
    last: "AV",
    age: 21,
    address: {
        housename: "good house",
        place: "goodplace",
        city: "goodtwon",
        postcode: 121212
    },
    hobbies: ["driving", "travelling", "sports"]
}, {
    fname: "ramu",
    last: "kv",
    age: 29,
    address: {
        housename: "etho veedu",
        place: "vayadi",
        city: "kalur",
        postcode: 11111
    },
    hobbies: ["travelling", "sports"]
}]
console.log(" objects::\t", Name, "\n", firstclass_employee)
    //calling a out side function for an object(out side function may be inside an object oe not)
console.log("Fullname of first employee::", Name.fullname.call(firstclass_employee[0]))
console.log("Pension status of of first emlpoyee::", pension.call(firstclass_employee[0]))
console.log("Fullname of 2nd employee::", Name.fullname.call(firstclass_employee[1]))
console.log("Pension status of of 2nd emlpoyee::", pension.call(firstclass_employee[1]))
AND getting error---> console.log("Fullname of first employee::", Name.fullname.call(firstclass_employee[0])) ^

TypeError: Name.fullname.call is not a function




Aucun commentaire:

Enregistrer un commentaire