JSFiddle - React, Tailwind, and code Playground
by Alexey
JavaScript
var User = /** @class */ (function () {
function User(name, age) {
this._name = name;
this._year = this.setYear(age);
}
User.prototype.displayYear = function () {
/* console.log("Год рождения: " + this._year) */;
};
User.prototype.displayName = function () {
/* console.log("name: " + this._name) */;
};
User.prototype.setYear = function (age) {
return new Date().getFullYear() - age;
};
return User;
}());
var tom = new User("Tom", 24);
tom.displayName();
tom.displayYear();
console.log(tom._name); // нельзя обратиться, так как _name - private
// tom.setYear(45); // нельзя обратиться, так как функция - private