What's the purpose of using Javascript Classes?
Classes are used to create and manage multiple Objects
Old Javascript class
function 붕어빵(title, ingredients){
this.title = title,
this.ingredients = ingredients
}
var 슈크림붕어빵 = new 붕어빵('슈크림붕어빵',['밀가루','물','슈크림','설탕'])
Modern Javascript class
class 모던붕어빵{
constructor(title, ingredients){
this.title = title,
this.ingredients = ingredients
}
}
let 피자붕어빵 = new 모던붕어빵('피자붕어빵',['밀가루','설탕','물','치즈','케쳡','소세지','양파','피망'])
//Typescript
class 모던붕어빵2{
title:string;
indegredients:string;
constructor(title2:string, ingredients2:string){
this.title = title2,
this.ingredients = ingredients2
}
}
prototype
the prototype property allows you to add properties and methods to any object.
function 게임(){
this.q = 'move left';
this.w = 'move right';
}
게임.prototype.name = '바람의나라'
var game = new 게임()
console.log(game.name)
if there is no name of game, javascript search '게임' prototype.
Array and Object have their own prototypes, so you can easily access them and coding!
반응형
'Frontend > 모던자바스크립트' 카테고리의 다른 글
이벤트 중복호출 아무리해도 해결안될때 (0) | 2022.10.06 |
---|---|
동기와 비동기(callbac, promise, async) (0) | 2022.05.29 |
배열함수 총정리 forEach(), Map(), filter() 등등 (0) | 2021.11.09 |
자료구조와 자료형 Object.keys, values, entries (0) | 2021.09.20 |
객체와 배열 구조분해할당(destructuring) (0) | 2021.09.20 |