<input id="field" type="text">
var $field = $('#field');
var model = {
_field: 'имя',
get field() {
return this._field;
},
set field(value) {
$field.val(value);
this._field = value;
}
};
$field.val(model.field);
$field.on('input', function() {
model.field = $(this).val();
});
class Field extends Component {
state = { value: 'имя' }
handleChange = (event) => {
this.setState({ value: event.target.value });
}
render() {
return <input type="text" value={this.state.value} onChange={this.handleChange}>
}
}
function User(name, birthday) {
this.name = name;
this.birthday = birthday;
// age будет высчитывать возраст по birthday
Object.defineProperty(this, "age", {
get: function() {
var todayYear = new Date().getFullYear();
return todayYear - this.birthday.getFullYear();
}
});
}
function Vehicle (name) {
this._name = name;
}
Object.defineProperty(Vehicle.prototype, 'name', {
get: function () { return this._name; },
set: function (value) { this._name = value }
});