[클래스] getter/setter

HeuiEun Choi·2023년 1월 18일
0

javascript

목록 보기
22/39
post-custom-banner

class User {
	constructor(first, last) {
    	this.firstName = fist
      	this.lastName = last
    }
  	get fullName(){
    	return `${this.fistName}  ${this.lastName}`
    }
  	set fullName(value){
      [this.fistName, this.lastName] = value.split(' ');
      
    }
  
}
const heropy = new User('Heropy', 'Park');
heropy.firstName = 'Neo';
console.log(heropy.fullName); //Heropy Park
 
heropy.fullName = 'Neo Anderson'
profile
당신을 한줄로 소개

0개의 댓글