Javascript methods | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

Javascript methods

function person(name, age) { this.name= name; this.age = age; this.yearOfBirth = bornYear; } function bornYear() { return 2016 - this.age; } in the above code we have this.yearOfBirth but i dont see it being defined beforehand or did i get it all wrong ??

20th Jul 2017, 10:11 PM
abdoullfurya
abdoullfurya - avatar
1 Antwort
0
'bornYear' is a function, so it should be with parentheses: this.yearOfBirth = bornYear(); When the above statement is executed, it calls the function 'bornYear()', which returns the needed value to the caller, so 'yearOfBirth' is assigned to that value.
21st Jul 2017, 12:24 AM
Boris Batinkov
Boris Batinkov - avatar