Giter Club home page Giter Club logo

closure's Introduction

클로저에 값 저장하기

  • 자바스크립트에는 값을 저장하기 위한 수단이 많은데, 클로저는 자바스크립트 엔진의 성질을 이용하는 방법.
  • react.js 는 클로저를 많이 사용하기 때문에, 이걸 한번 짚고 넘어가면 react.js 를 배우실때 도움이 될 것 같다.
  • 신입사원이 입사했을때 코드를 설명하기 위해 만들었던 자료로 설명을 해 보려고 한다(결국은 react.js를 모르는 경력자에게 설명했던게 함정).
  • 순서는 아래와 같다
  1. 실행 컨텍스트
  2. 클로저
  3. react.js의 useState
  4. use*

실행 컨텍스트

  1. 실행 컨텍스트를 눈으로 확인해 봅시다.
  2. 자바스크립트 엔진은 자바스크립트 파일을 읽어서 실행컨텍스트 라는것을 만든다.
  3. 실행컨텍스트는 함수마다 만들어진다.
  4. 실행컨텍스트가 함수를 실행하기 전에 만들어진다는걸 기억하자.
  5. 함수가 호출되면 실행컨텍스트가 콜 스택에 쌓인다.

클로저

  1. 그 다음에 클로저를 눈으로 확인해야 한다
  2. 자바스크립트의 함수는 바깥함수의 변수도 읽거나 쓸 수 있어야 한다.
  3. 그래서 자바스크립트 엔진은 안쪽함수의 실행 컨텍스트에 바깥함수의 정보를 넣어버린다.
  4. 안쪽함수가 가지고 있는 바깥함수의 정보를 클로저라고 한다
  5. 실행컨텍스트가 함수를 실행하기 전에 만들어진다는걸 기억하자
  6. 클로저는 함수를 실행하기 전에 만들어진다

useState

  1. 클로저는 값을 저장하는 저장소로 사용할 수 있다.
  2. react.js 의 함수형 컴포넌트는 값을 저장할때 useState라는 함수를 사용한다.

closure's People

Contributors

ovelute53 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.