JSFiddle - React, Tailwind, and code Playground
HTML
<div id="out"></div>
JavaScript
function Person(args) {
if (args.name) { this.name = args.name; }
if (args.birthday) { this.birthday = args.birthday; }
if (args.children) { this.children = args.children; }
}
// Person properties and methods
Person.prototype = {
name: { value: "", writable: true },
birthday: { value: new Date(), writable: true },
age: { get: function () { return Math.floor((new Date() - this.birthday) / 31557600000); } },
children: { value: [], writable: true },
toString: { value: function () { return this.name + " (" + this.age + ")"; } }
};
var tom = new Person({ name: "tom", birthday: new Date(1995, 7, 30) });
var john = new Person({ name: "john", birthday: new Date(1994, 4, 5) });
var chris = new Person({ name: "chris", birthday: new Date(1969, 5, 2), children: [tom, john] });
var people = [tom, john, chris];
console.log(chris.name);
for(var key in tom ) {
out.innerHTML += "<p>" + key + "= " + tom[key] + "</p>";
}
var tomPrototype = Object.getPrototypeOf(tom);
for(var key in tomPrototype ) {
out.innerHTML += "<p>" + key + "= " + tomPrototype[key] + "</p>";
}