JAMONGPROJECT

220425 본문

Challenge/엘리스 SW Engineer 2기

220425

JAMONGPROJECT 2022. 4. 26. 17:56

./ -> 현재 폴더를 의미

../ -> 상위 폴더를 의미

 

import / export : <script type = "module"> 로 가져옴

 

리액트에서 component 개념을 많이 쓰기때문에 숙지.

 

const로 정의하면 객체의 주소 기준으로 고정이 되는 것임. 따로 공부하자.

 

JSON.parse(JSON.stringify(person))

딥카피 방식

 

클래스 활용

 

class Person {
    firstName;
    lastName;
    age;

    // 생성자
    constructor(name, age) {
        this.setName(name)
        this.age = age;
    }

    setName(name) {
        let tmp = name.split(" ");
        if (tmp.length < 1) {
            console.log("Error: wrong input!");
            return;
        }

        this.firstName = tmp[0]
        if (tmp.length >= 2)
            this.lastName = tmp[1]
    }

    getName() {
        return this.name;
    }

    setAge(age) {
        this.age = age;
    }

    getAge() {
        return this.age + "세";
    }
}

let john = new Person("John Park", 30);
let bob = new Person("Bob", 27);

console.log(john.getName());
console.log(john.getAge());
console.log(bob.getName());
console.log(bob.getAge());

 

export 할때 보통 class 를 export default로 내보낸다.

 

 

 

#class에서의 상속

 

class User extends Person {

    level;

}

 

부모의 class 요소가 extends를 통해 자식 요소에 상속될수있다.

 

this => 자기 객체를 가리키는것

'Challenge > 엘리스 SW Engineer 2기' 카테고리의 다른 글

220502  (0) 2022.05.02
220427  (0) 2022.04.27
자동차 경주 문제  (0) 2022.04.23
220420  (0) 2022.04.20
220418  (0) 2022.04.18
Comments