JSFiddle - React, Tailwind, and code Playground
JavaScript
function User(fullName) {
this.fullName = fullName;
Object.defineProperties(this, {
'firstName': {
get() {
let split = this.fullName.split(' ');
this.firstName = split[0];
}
},
'lastName': {
get() {
let split = this.fullName.split(' ');
this.lastName = split[1];
}
}
})
};
var vasya = new User("Василий Попкин");
console.log(vasya.firstName); //undefined
console.log(vasya.lastName); //undefined