+ 1
Why it is not possible to call the getName method of the assigned Person object from the Citizen class?
4 odpowiedzi
+ 5
look at the answer with 200+ votes
https://stackoverflow.com/questions/22156326/private-properties-in-javascript-es6-classes
+ 4
Your Citizen constructor should be:
this._obj = person_object;
Also in the Person constructor, when declaring as "var _age = age;" you will not have access to that variable inside the class methods.
it should be this._age = age; and same for name, no need to declare var for it inside the condtructor
+ 4
The answers in that post that I was going to suggest are:
https://stackoverflow.com/a/28165599
https://stackoverflow.com/a/22509411
0
I am a little bit in trouble with JS ... That works but it makes all the properties public.