when i want that the property get year to print, i cant acces to the variable I have this obj:
let human = {
birdYear: 1,
getAge: (function (birdYear) {
return 2021 - this.birdYear
})()
};
when print human get this:
Cannot read property 'birdYear' of birdYear
and i want get this:
{
birdYear: 1
getAge: 2020
}
some cane help me? I thy with using:
- 'this.'
- without 'this.birdYear'
- (fn(birdYear){...birdYear})()
- (fn(birdYear){...birdYear})(this.birdYear)
and nothing
THANKS
// ADD
i found this way
let human = {
birdYear: 1,
get getAge() {
return new Date().getFullYear() - this.birdYear
}
};
Works! I only need to understand why not I use IIFE as methods...