![](http://i1.daumcdn.net/thumb/C148x148.fwebp.q85/?fname=https://blog.kakaocdn.net/dn/bmzNYD/btqCAO92hm2/88WD5CT5NWyIG7Cu2Rj2r0/img.png)
Model에는 instance method 말고도 static functions가 있다. 잠깐 설명을 하자면 javascript 클래스에는 static이라는 개념이 있다. 일반적으로 method를 클래스에 선언하면 그 method의 this는 인스턴스에 바인딩된다. static method에서 this는 클래스 그 자체에 바인딩된다. schema 정의. const animalSchema = new Schema({ name: String, breed: String }) static method 정의. // Assign a function to the "statics" object of our animalSchema animalSchema.statics.findByName = function (name) {..
![](http://i1.daumcdn.net/thumb/C148x148.fwebp.q85/?fname=https://blog.kakaocdn.net/dn/brkEGg/btqCym0WMRc/MibrOVScztd0IizR1Q6NIk/img.png)
documents는 Model 클래스에 instance들이다. 저장한 data 이외에도 많은 built-in-instance methods를 가지고 있다. 물론 우리가 custom methods를 만들 수도 있다. schema 인스턴스에 methods 프로퍼티에 findSimilarTypes라는 instance method를 정의해 준다. const animalSchema = new Schema({ name: String, type: String, breed: String }); // overwritting a default mongoose doucment method may lead to unpredictable results. animalSchema.methods.findSimilarTypes = f..
![](http://i1.daumcdn.net/thumb/C148x148.fwebp.q85/?fname=https://blog.kakaocdn.net/dn/c72Tii/btqCB9ztB16/kH10dfG3RvJzH2eCklD9S1/img.jpg)
배열(리스트)은 크기가 고정되어 있고, 중간에 다른 원소를 넣고 빼려면 다른 원소들까지 옮겨야 하므로 비싼 연산을 수반한다. 연결 리스트는 일련의 원소를 배열처럼 차례대로 저장하지만, 원소들이 메모리상에 연속적으로 위치하지 않는다. 리스트는 참조 정보가 포함된 Node로 구성된다. Node(Head) -> Node ->... -> Node -> NULL LinkedList 클래스 class LinkedList { constructor() { this.length = 0; // 전체 Node 개수 this.head = null; // 첫 Node } } Node 정의. LinkedList.prototype.Node = class Node { constructor(element) { this.element ..
![](http://i1.daumcdn.net/thumb/C148x148.fwebp.q85/?fname=https://blog.kakaocdn.net/dn/cBAaEB/btqCrOp4t6p/05IitpJQmmorL8AvuHOCk1/img.jpg)
Stack, Queue, linked List 같은 자료구조들은 순차(Sequential) 자료구조다. 집합(Set)은 정렬되지 않은(unordered)컬렉션으로 원소는 반복되지 않는다.(중복허용 x) ES6에서 Set이 추가되었다. Set을 한번 직접 만들어보고 필요한 기능도 추가해보자. this.items는 원소가 들어갈 객체, this.index는 원소가 들어갈 다음위치(마지막index + 1). class Set{ constructor() { this.items = {}; this.index = 0; } } has메서드는 해당 value값을 가지고 있는지 여부 판단 has(value) { let keys = Object.keys(this.items); for (let i in keys) { if ..
![](http://i1.daumcdn.net/thumb/C148x148.fwebp.q85/?fname=https://blog.kakaocdn.net/dn/bjqZRK/btqCuZRyq8R/DuW1Cte6rXFeO0yx02nrx1/img.png)
보통 node.js프로세스는 cpu코어 하나를 사용한다. 멀티코어 cpu를 사용하고 있을 경우 node.js는 여러 개의 cpu코어를 사용할 수 있게 해주는데 그럴 때 사용하는 것이 cluster이다. cluster모듈은 코어 하나당 노드 프로세스를 돌아가게 할 수 있다. cluster 자신의 PC의 cpu 코어개수 확인. const numCPUs = require('os').cpus().length; console.log(numCPUs); // 4 cluster에는 master 프로세스와 worker 프로세스가 있다. master프로세스는 cpu개수만큼 워커 프로세스를 만들고, 8005번 포트에서 대기하면서 요청이 들어왔을 때 worker 프로세스에 요청을 분배한다. const numCPUs = req..
- Total
- Today
- Yesterday
- static method
- map
- mixin
- mongoose
- index
- javascript
- 자료구조 #딕셔너리 #해시
- alias
- resave
- 다중상속
- set
- 집합
- 맵
- Iterator
- 선형리스트
- query helper
- 자료구조
- Generator
- instance method
- pm2 #cluster #Javascript
- Node.js
- express-session
- saveUnitialized
- 다형성
- MongoDB
- virtuals
- 이중 연결리스트
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |