JAMONGPROJECT
220425 본문
./ -> 현재 폴더를 의미
../ -> 상위 폴더를 의미
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 => 자기 객체를 가리키는것
Comments