Last active
April 24, 2017 10:29
-
-
Save uyu423/fa27377b768f3d9c78ed3256f2efdc6b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Money { | |
| constructor(value) { | |
| if (value < 0) throw Error('Money Type Valiation Exception'); | |
| this.value = value; | |
| } | |
| } | |
| class Email { | |
| constructor(email) { | |
| const regExp = /^[0-9a-zA-Z]([-_\.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_\.]?[0-9a-zA-Z])*\.[a-zA-Z]{2,3}$/i; | |
| if (!regExp.test(email)) throw Error('Email Type Validation Exception') | |
| this.email = email; | |
| Object.defineProperty(this, 'username', { | |
| value: email.split('@')[0], | |
| enumerable: false, | |
| }); | |
| Object.defineProperty(this, 'domain', { | |
| value: email.split('@')[1], | |
| enumerable: false, | |
| }); | |
| } | |
| } | |
| class User { | |
| constructor(object) { | |
| this.name = object.name; | |
| this.credit = new Money(object.credit); | |
| this.email = new Email(object.email); | |
| } | |
| } | |
| const yowu = new User({ | |
| name: 'Yowu', | |
| credit: 10000, | |
| email: 'yowu@plating.co.kr', | |
| }); | |
| console.log(yowu); | |
| // Real Output | |
| // User { | |
| // name: 'Yowu', | |
| // credit: Money { value: 10000 }, | |
| // email: Email { email: 'yowu@plating.co.kr' } } | |
| // 아래와 같이 출력되게 하는 방법이 있을까.. | |
| // User { | |
| // name: 'Yowu', | |
| // credit: 10000, | |
| // email: 'yowu@plating.co.kr' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
David Seunghoon Ko 님이 제시해주신 코드 (https://www.facebook.com/groups/codingeverybody/permalink/1642888369085026/)
