Giter VIP home page Giter VIP logo

Comments (2)

leemember avatar leemember commented on July 17, 2024

๋™์  ๋ฐ”์ธ๋”ฉ

  • ํ˜„์žฌ this๋Š” ๋ˆ„๊ตฌ์ธ์ง€ ๋ชจ๋ฅธ๋‹ค.

์ž๋ฐ”, C#, C++ ๋Œ€๋ถ€๋ถ„์˜ ๊ฐ์ฒด์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์—์„œ๋Š” this๋Š” ํ•ญ์ƒ ์ž์‹ ์˜ ์ธ์Šคํ„ด์Šค ์ž์ฒด๋ฅผ ๊ฐ€๋ฆฌํ‚จ๋‹ค. ์ •์ ์œผ๋กœ ์ธ์Šคํ„ด์Šค๊ฐ€ ๋งŒ๋“ค์–ด์ง€๋Š” ์‹œ์ ์— this๊ฐ€ ๊ฒฐ์ •๋œ๋‹ค๋Š” ๋œป์ด๋‹ค. ํ•˜์ง€๋งŒ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ๋Š” ๋ˆ„๊ฐ€ ํ˜ธ์ถœํ•˜๋ƒ์— ๋”ฐ๋ผ this๊ฐ€ ๋‹ฌ๋ผ์ง„๋‹ค. ์ฆ‰, this๋Š” ํ˜ธ์ถœํ•˜๋Š” ์‚ฌ๋žŒ(=caller)์— ์˜ํ•ด ๋™์ ์œผ๋กœ ๊ฒฐ์ •์ด ๋œ๋‹ค.

from fe_growing.

leemember avatar leemember commented on July 17, 2024

์ •์  ๋ฐ”์ธ๋”ฉ

this๋ผ๋Š” ํ•จ์ˆ˜๊ฐ€ ๊ณ„์† ๋™์ ์œผ๋กœ ๋ณ€๊ฒฝ๋˜๊ธฐ ๋•Œ๋ฌธ์— ์ด๊ฑธ ์ •์ ์œผ๋กœ ๊ฝ๊ฝ ์–ผ๋ ค๋ฒ„๋ฆฌ๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค.

1. bind ๋ผ๋Š” ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด์„œ ์ˆ˜๋™์ ์œผ๋กœ ๋ฐ”์ธ๋”ฉ ํ•ด์ค€๋‹ค.

this.printName = this.printName.bind(this)

์กฐ๊ธˆ ๋” ๊ฐ„ํŽธํ•˜๊ฒŒ ํ•˜๋Š” ๋ฐฉ์‹์ด ์žˆ๋‹ค.
ํ•จ์ˆ˜ ํ™”์‚ดํ‘œ ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

2. arrow ํ•จ์ˆ˜ ์‚ฌ์šฉ

  • arrow ํ•จ์ˆ˜๋Š” ๋ ‰์‹œ์ปฌ ํ™˜๊ฒฝ์—์„œ this๋ฅผ ๊ธฐ์–ตํ•œ๋‹ค.
this.printName = () => {
 consolel.og('์•ˆ๋…• ${this.name}`);
}

์ด๋Ÿฐ ์‹์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜๊ฐ€ ์žˆ๋‹ค.


ํ™”์‚ดํ‘œ ํ•จ์ˆ˜ ํŠน์ง•

  1. ๋ฌธ๋ฒ•์ด ๊น”๋”ํ•˜๋‹ค
  2. ์ƒ์„ฑ์ž ํ•จ์ˆ˜๋กœ ์‚ฌ์šฉ์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค (๋ฌด๊ฑฐ์šด ํ”„๋กœํ† ํƒ€์ž…์„ ๋งŒ๋“ค์ง€๋ง์ž)
  3. ํ•จ์ˆ˜ ์ž์ฒด arguments
  4. this์— ๋Œ€ํ•œ ๋ฐ”์ธ๋”ฉ์ด ์ •์ ์œผ๋กœ ๊ฒฐ์ •๋œ๋‹ค
  • ํ•จ์ˆ˜์—์„œ ์ œ์ผ ๊ทผ์ ‘ํ•œ ์ƒ์œ„ ์Šค์ฝ”ํ”„์˜ this์— ์ •์ ์œผ๋กœ ๋ฐ”์ธ๋”ฉ๋œ๋‹ค.

from fe_growing.

Related Issues (20)

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.