# 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]"

vuepress

# Reference


https://www.inflearn.com/course/es6-๊ฐ•์ขŒ-์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ/dashboard (opens new window)

https://jsbin.com/ (opens new window)

Last Updated: 2021-10-27