# 15. JavaScript CLASS !
๐ ์๋ JavaScript์๋ ํด๋์ค๊ฐ ๋ฐ๋ก ์กด์ฌํ์ง ์๋๋ฐ, ES6๋ถํฐ ํด๋์ค๊ฐ ์๊ฒผ๋ค!
# โจ ์ผ๋ฐ์ ์ธ function
function Health(name) {
this.name = name;
}
Health.prototype.showHealth = function() {
console.log(this.name + "๋, ์๋
ํ์ธ์");
}
const h = new Health("damoo");
h.showHealth();
# ๐ console
"damoo๋, ์๋
ํ์ธ์"
# โจ class
๋ชจ์ต๋ง class ์ด์ง, prototype์ผ๋ก ๊ตฌํ๋๋ค.
class Health {
constructor(name, lastTime) {
this.name = name;
this.lastTime = lastTime;
}
showHealth() {
console.log("์๋
ํ์ธ์, " + this.name + "๋");
}
}
const myHealth = new Health("damoo");
myHealth.showHealth();
console.log(toString.call(Health));
# ๐ console
"์๋
ํ์ธ์, damoo๋"
"[object Function]"

# Reference
https://www.inflearn.com/course/es6-๊ฐ์ข-์๋ฐ์คํฌ๋ฆฝํธ/dashboard (opens new window)