JSFiddle - React, Tailwind, and code Playground
HTML
Здесь проживают:
<ul id="mankind">
</ul>
JavaScript
var mankindList = document.getElementById("mankind");
function World() {
this.mankind = new Mankind(this);
this.getName = function(id) {
return this.mankind.people[id].name;
}
//Геттер для массива всех людей
this.getPeople = function() {
return this.mankind.people
}
//Вывод имен людей на экран
this.showPeople = function() {
mankindList.innerHTML = "";
var people = this.getPeople();
for (var p in people) {
var person = document.createElement("LI");
person.innerHTML = people[p].name;
mankindList.appendChild(person);
};
};
//alert(this.getName(0));
//alert('Здесь проживают: ' + this.mankind.city.map(this.getName));
}
function Mankind(world) {
this.people = new Array();
this.people[0] = new Man(this, 'Vasily');
this.people[1] = new Man(this, 'Alessandra');
this.city = [0, 1];
}
function Man(mankind, name) {
//mankind осталось не прибинженным в изначальном примере
this.mankind = mankind;
this.name = name;
}
var dummyWorld = new World();
dummyWorld.showPeople();