Created
March 9, 2020 03:26
-
-
Save chiro-hiro/1ebc61c54af9573e6429d858e8f4e062 to your computer and use it in GitHub Desktop.
This file contains 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 Human { | |
constructor(name) { | |
this.name = name; | |
this.race = 'Terran'; | |
} | |
set name(value) { | |
if (typeof value !== 'string') { | |
throw new TypeError('Name value was not a string'); | |
} | |
this._name = value | |
.split(' ') | |
.map(function (item) { | |
return item[0].toUpperCase() + item.substring(1); | |
}) | |
.join(' '); | |
} | |
get name() { | |
throw new Error('This value can not be read by this way'); | |
} | |
getName() { | |
return this._name; | |
} | |
} | |
class Man extends Human { | |
constructor(name) { | |
super(name); | |
this.gender = 'Male'; | |
} | |
} | |
const instanceHuman = new Human('chiro hiro'); | |
console.log('My name is:', instanceHuman.getName(), 'Race:', instanceHuman.race); | |
const instanceMan = new Man('Some body we used to know'); | |
console.log('My name is:', instanceMan.getName(), 'Race:', instanceMan.race, 'Gender:', instanceMan.gender); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment