Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Node.js기본
- partitioning
- SSE
- node.js란
- localStorage
- PostgreSQL
- ServerSentEvent
- 실시간알림
- mariadb
- Lag
- 성장기
- frontend
- EventSource
- 개발자
- Partition
- 열공하자
- node.js
- 파티셔닝
Archives
- Today
- Total
써치킴의 우당탕탕 개발 블로그
[JS Essentials][Ch2][클래스] ES6 Classes 본문
축약형 일반함수를 사용할 수 있다.
normal : function () { -> normal()
const searchkim = {
name : 'SearchKim',
// normal : function () {
// -> normal()
normal() { // 축약형 일반함수
console.log(this.name);
},
arrow : () => { // 화살표 함수
console.log(this.name);
}
}
searchkim.normal();
searchkim.arrow();
자바스크립트는 프로토타입 기반의 프로그래밍 언어인데
안정적이고 효율이 높은 다른 객체지향 프로그래밍 언어의 영향을 받아서
'클래스'라는 개념을 흉내내 새로운 문법을 ES6에서 제공하기 시작했다.
/* function User(first, last) { // 생성자 함수
this.firstName = first;
this.lastName = last;
}
User.prototype.getFullName = function () { // prototype 속성에 함수를 만들어주면 메모리에 한번만 생성됨
return `${this.firstName} ${this.lastName}`; // 데이터 보관
} */
class User {
// constructor: function(first, last){ 와 같다.
constructor(first, last){
this.firstName = first;
this.lastName = last;
}
// class를 사용하면 프로토타입 속성을 사용하지 않아도 프로토타입 메소드가 정의된다.
getFullName(){
return `${this.firstName} ${this.lastName}`; // 데이터 보관
}
}
const search = new User('Search', 'Kim');
const amy = new User('Amy', 'Kim');
const neo = new User('Neo', 'Kim');
console.log(search.getFullName());
console.log(amy.getFullName());
console.log(neo.getFullName());
class를 사용하면 프로토타입 속성을 사용하지 않아도 프로토타입 메소드가 정의된다!
'파도파도 나오는 JavaScript' 카테고리의 다른 글
[JS Level up][Ch1][데이터] 문자 (0) | 2022.01.28 |
---|---|
[JS Essentials][Ch2][클래스] 상속(확장) (0) | 2022.01.28 |
[JS Essentials][Ch2][클래스] this (0) | 2022.01.28 |
[JS Essentials][Ch2][클래스] 생성자 함수(prototype) (0) | 2022.01.28 |
[JS Essentials][Ch2][함수] 콜백 (Callback) (0) | 2022.01.28 |
Comments