# 20210218(목)

## 2021-02-18

### 1. 학습 날짜

* 2021-02-18

### 2. 학습 시간

* 11:00 \~ 24:00

### 3. 학습 범위 및 주제

* 백본 view, model, collection
* 루비온레일즈

### 4. 학습 목표

* 레일즈 DB 학습&#x20;

### 5. 학습 정리

* x

### 6. 상세 학습 내용

* 백본 js의 모델과 컬렉션에는 fetch 함수가 있다.
* 이전에는 함수에 success\_callback 과 fail\_callback이 없다고 생각해서 사용하고 있지 않았는데 알아본 결과 존재하고 있었다.
* 사용하기 위해서는 아래처럼 하면된다.
* 들어오는 인자 3개는 현재 collection, 리턴 값 그리고 그외의 값들

```
this.fetch({
    success: function (collection, response, options) {
        ...
    ,
    error: function () {
        ...
    }

})
```

* 자바스크립트에서 this
* 아래의 코드가 있다고 하자

```
  showInfoMatchImposibleAndClose: function (user_model) {
    if (
      this.el.id == "rule-modal-view" ||
      user_model.get("status") == "offline"
    ) {
      Helper.info({
        subject: "게임 진행 불가능",
        description: "상대방이 게임 진행이 불가능한 상태입니다.",
      });
      this.close();
    }
  },

  addLitsenToUserModel: function (view, user_id) {
    let user_model = this.getUserModelInAppearanceCollections(user_id);

    if (user_model == undefined || user_model.get("status") == "offline") {
      return false;
    }
    view.listenTo(
      user_model,
      "change:status",
      this.showInfoMatchImposibleAndClose
    );

    return true;
  },
```

* `showInfoMatchIm...` 함수에서의 this 는 view가 된다.
* 왜 그런가?
* `view.listenTo(..)` 의 콜백 함수로 넘어갔고, 그 함수가 실행되는 맥락은 `view` 기 때문이다.

### 7. 오늘 학습 내용에 대한 개인적인 총평

* 흠 정말 짜증나는 과제다 얼른 끝내고 싶다.

### 8. 다음 학습 계획

* guild detail 뷰


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://simian114.gitbook.io/blog/undefined-1/diary/2021/february/20210218.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
