자바스크립트 객체 패턴 총정리

dev.dave·2023년 7월 24일

Javascript

목록 보기
27/167

//자바스크립트 객체 표현 패턴 총정리

//객체 리터럴 방법
// const Cars = {
// init(name, year) {
// this.carName = name;
// this.carYear = year;
// },
// getCarName() {
// this.carName;
// },
// getCarYear() {
// this.carYear;
// },
// getCarInfo() {
// return name: ${this.carName}, year: ${this.carYear};
// },
// };
// Cars.init("moning", 2003);
// Cars.getCarInfo();

//클래스 Class
// class Cars {
// constructor(name, year) {
// this.carName = name;
// this.carYear = year;
// }

// getCarName() {
// this.carName;
// }

// getCarYear() {
// this.carYear;
// }

// getCarInfo() {
// return name: ${this.carName}, year: ${this.carYear};
// }
// }

// const car = new Cars("morning, 2003");
// console.log(car.getCarInfo());

//
//프로토 타입 적용 (지금은 안쓰는 방법)
// function Cars(name, year) {
// this.carName = name;
// this.carYear = year;
// } // return this;

// Cars.prototype.getCarName = function () {
// this.carName;
// };

// Cars.prototype.getCarYear = function () {
// this.carYear;
// };

// Cars.prototype.getCarInfo = function () {
// return name: ${this.carName}, year: ${this.carYear};
// };

// const car = new Cars("morning, 2003");
// console.log(car.getCarInfo());

profile
🔥개인 메모 / 다른블로그 자료 참조 / 다른블로그 자료 퍼옴 (출처표기) /여기저기서 공부 했던 내용 개인메모 & 참고 / 개인 기록 용도 블로그 입니다.🔥

0개의 댓글