๐ปClass
class Person()
class Person(){
name = 'kim'
age = 30
heigth = 190
weight = 100
}
.
์ฐ์ฐ์๋ฅผ ์ฌ์ฉํ๋ค.class Person(){
name = 'kim'
age = 30
heigth = 190
weight = 100
}
const kim = new Person()
kim.name
kim.age
kim.height
kim.weight
class Person{
name = 'kim'
age = 20
height = 180
weight = 100
constructor(name, age, height, weight){
if(name) this.name = name
if(age) this.age = age
if(height) this.height = height
if(weight) this.weight = weight
}
}
const lee = new Person('lee', 30, 170, 50)
console.log('lee: ', lee);
const lee = new Person('lee', 30, 170, 50)
๋ฉค๋ฒํจ์
๋๋ ๋ฉ์๋
๋ผ๊ณ ๋ถ๋ฅธ๋ค.class Person {
name = 'kim'
age = 30
height = 190
weight = 100
sayHi() {
console.log('Hi !!')
}
}
const kim = new Person()
kim.sayHi()
class Person{
name = 'kim'
age = 20
height = 180
weight = 100
sayMyName(){
console.log(this.name)
}
}
const lee = new Person('lee', 30, 170, 50)
lee.sayMyName() //lee
class Person{
name = 'kim'
age = 20
height = 180
weight = 100
constructor(name,age,height,weight){
this.name = name
this.age = age
this.height = height
this.weight = weight
}
sayMyName(){
console.log(this.name)
}
changeMyage(newAge){
this.age = newAge
}
}
const lee = new Person('lee', 30, 170, 50)
const newAge = lee.changeMyage(20)
console.log('lee: ', lee); //{ name: 'lee', age: 20, height: 170, weight: 50 }
class forThisClass{
showThis(){
console.log(this)
}
}
const test = new forThisClass()
test.showThis() //forThisClass
[.bind()]
class forThisClass{
showThis(){
document.onclick = function(){
console.log(this)
}.bind(this)
}
}
const test = new forThisClass()
test.showThis()
class Person{
constructor(name){
this.name = name
}
static sayHi(){
console.log(`Hi!`)
}
}
Person.sayHi() //Hi
class Animal{
constructor(age, weight){
this.age = age
this.weight = weight
}
eat(){ return 'eat' }
move(){ return 'move' }
}
class Brid extends Animal{
fly(){return 'fly'}
}
const brid = new Brid(1, 5)
console.log('brid: ', brid);
console.log(brid.eat())
console.log(brid.move())
console.log(brid.fly())
์์์ ํตํด ํ์ฅ๋ ํด๋์ค๋ฅผ ์๋ธํด๋์ค
๋ผ๊ณ ๋ถ๋ฅธ๋ค.
์๋ธํด๋์ค์ ์์๋ ํด๋์ค๋ฅผ ์ํผํด๋์ค
๋ผ๊ณ ๋ถ๋ฅธ๋ค.
์๋ธํด๋์ค๋ฅผ ํ์ํด๋์ค
๋๋ ์์ํด๋์ค
๋ผ๊ณ ๋ถ๋ฅด๊ธฐ๋ ํ๋ค.
์ํผํด๋์ค๋ฅผ ๋ฒ ์ด์คํด๋์ค
๋๋ ๋ถ๋ชจํด๋์ค
๋ผ๊ณ ๋ถ๋ฅด๊ธฐ๋ ํ๋ค.
extends ํค์๋์ ์ญํ ์ ์ํผ ํด๋์ค์ ์๋ธํด๋์ค ๊ฐ์ ์์ ๊ด๊ณ๋ฅผ ์ค์ ํ๋ ๊ฒ์ด๋ค.
ํด๋์ค๋ ํ๋กํ ํ์ ์ ํตํด ์์ ๊ด๊ณ๋ฅผ ๊ตฌํํ๋ค.