Comments (2)
๋์ ๋ฐ์ธ๋ฉ
- ํ์ฌ this๋ ๋๊ตฌ์ธ์ง ๋ชจ๋ฅธ๋ค.
์๋ฐ, C#, C++ ๋๋ถ๋ถ์ ๊ฐ์ฒด์งํฅ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด์์๋ this๋ ํญ์ ์์ ์ ์ธ์คํด์ค ์์ฒด๋ฅผ ๊ฐ๋ฆฌํจ๋ค. ์ ์ ์ผ๋ก ์ธ์คํด์ค๊ฐ ๋ง๋ค์ด์ง๋ ์์ ์ this๊ฐ ๊ฒฐ์ ๋๋ค๋ ๋ป์ด๋ค. ํ์ง๋ง ์๋ฐ์คํฌ๋ฆฝํธ์์๋ ๋๊ฐ ํธ์ถํ๋์ ๋ฐ๋ผ this๊ฐ ๋ฌ๋ผ์ง๋ค. ์ฆ, this๋ ํธ์ถํ๋ ์ฌ๋(=caller)์ ์ํด ๋์ ์ผ๋ก ๊ฒฐ์ ์ด ๋๋ค.
from fe_growing.
์ ์ ๋ฐ์ธ๋ฉ
this๋ผ๋ ํจ์๊ฐ ๊ณ์ ๋์ ์ผ๋ก ๋ณ๊ฒฝ๋๊ธฐ ๋๋ฌธ์ ์ด๊ฑธ ์ ์ ์ผ๋ก ๊ฝ๊ฝ ์ผ๋ ค๋ฒ๋ฆฌ๋ ๋ฐฉ๋ฒ์ด ์๋ค.
1. bind ๋ผ๋ ํจ์๋ฅผ ์ด์ฉํด์ ์๋์ ์ผ๋ก ๋ฐ์ธ๋ฉ ํด์ค๋ค.
this.printName = this.printName.bind(this)
์กฐ๊ธ ๋ ๊ฐํธํ๊ฒ ํ๋ ๋ฐฉ์์ด ์๋ค.
ํจ์ ํ์ดํ ๋ฐฉ์์ ์ฌ์ฉํ๋ฉด ๋๋ค.
2. arrow ํจ์ ์ฌ์ฉ
- arrow ํจ์๋ ๋ ์์ปฌ ํ๊ฒฝ์์ this๋ฅผ ๊ธฐ์ตํ๋ค.
this.printName = () => {
consolel.og('์๋
${this.name}`);
}
์ด๋ฐ ์์ผ๋ก ์ฌ์ฉํ ์๊ฐ ์๋ค.
ํ์ดํ ํจ์ ํน์ง
- ๋ฌธ๋ฒ์ด ๊น๋ํ๋ค
- ์์ฑ์ ํจ์๋ก ์ฌ์ฉ์ด ๋ถ๊ฐ๋ฅํ๋ค (๋ฌด๊ฑฐ์ด ํ๋กํ ํ์ ์ ๋ง๋ค์ง๋ง์)
- ํจ์ ์์ฒด arguments
- this์ ๋ํ ๋ฐ์ธ๋ฉ์ด ์ ์ ์ผ๋ก ๊ฒฐ์ ๋๋ค
- ํจ์์์ ์ ์ผ ๊ทผ์ ํ ์์ ์ค์ฝํ์ this์ ์ ์ ์ผ๋ก ๋ฐ์ธ๋ฉ๋๋ค.
from fe_growing.
Related Issues (20)
- ๐ ์๋ฐ์คํฌ๋ฆฝํธ ํน์ง 8 (๋ฐฐ์ด / ๊ณ ์ฐจํจ์)
- ๐ฅ ์๋ฐ์คํฌ๋ฆฝํธ ํน์ง 9 (์ดํฐ๋ฌ๋ธ, ์ ๋๋ ์ดํฐ)
- ๐ ์๋ฐ์คํฌ๋ฆฝํธ ํน์ง 10 (Set, Map) HOT 1
- ๐ ์๋ฐ์คํฌ๋ฆฝํธ ํน์ง 11 (์ฐ์ฐ์)
- ๐งฉ ์๋ฐ์คํฌ๋ฆฝํธ์ ํน์ง 12 (์ฃผ์, ์๋ฌ์ฒ๋ฆฌ, ๋ชจ๋ํ)
- ๐ ์๋ฐ์คํฌ๋ฆฝํธ ํน์ง 13 (๋น๋๊ธฐ) HOT 2
- ๐ ์๋ฐ์คํฌ๋ฆฝํธ ๊ธฐ์ ๋ฉด์ ๋จ๊ณจ ๊ฐ๋ ๋ค 1 (์ค์ฝํ, ๊ฐ๋น์ง ์ปฌ๋ ํฐ, ๋ ์์ปฌ ํ๊ฒฝ, ํธ์ด์คํ , var ๋ณ์, ์๊ฒฉ๋ชจ๋) HOT 4
- ๐ ์๋ฐ์คํฌ๋ฆฝํธ ๋ฉด์ ๋จ๊ณจ ๊ฐ๋ ๋ค 2 (ํ๋กํ ํ์ ) HOT 3
- ๐ถ ์๋ฐ์คํฌ๋ฆฝํธ ๋ฉด์ ๋จ๊ณจ ๊ฐ๋ ๋ค 3 (ํด๋ก์ ธ) HOT 1
- ๐๐ปโโ๏ธ ์๋ฐ์คํฌ๋ฆฝํธ ๋ฉด์ ๋จ๊ณจ ๊ฐ๋ ๋ค 5 (๋ฐ๋ฒจ)
- [๋ธ๋ผ์ฐ์ ] Web APIs (window)
- ๐ฟ ์๋ฃ๊ตฌ์กฐ ๊ฐ๋ ์ ๋ฆฌ (1) ์๊ฐ๋ณต์ก๋, ๋น ์ค ํ๊ธฐ๋ฒ, ๋ฐฐ์ด, ์ฐ๊ฒฐ๋ฆฌ์คํธ
- ๐ฟ ์๋ฃ๊ตฌ์กฐ ๊ฐ๋ ์ ๋ฆฌ (2) ์คํ, ํ, ๋ฑ, ํด์ํ ์ด๋ธ, ์
- ๐ข HTTP ๊ฐ๋ ์์๊ฐ๊ธฐ : IP ํ๋กํ ์ฝ์ ํ๊ณ
- ๐ข HTTP ๊ฐ๋ ์์๊ฐ๊ธฐ (2) : PORT ์ DNS
- ๐ข HTTP ๊ธฐ๋ณธ, ์ญ์ฌ, ํด๋ผ์ด์ธํธ ์๋ฒ ๊ตฌ์กฐ, ๋ฌด์ํ ํ๋กํ ์ฝ, ๋น ์ฐ๊ฒฐ์ฑ, HTTP ๋ฉ์์ง
- ๐ช ์ฟ ํค์ ๋ก์ปฌ ์คํ ๋ฆฌ์ง / ์ธ์ ์คํ ๋ฆฌ์ง
- ๐๐ปโโ๏ธ axios์ react-query ! react-query ๋์ ํด์ ์ข์์
- ๐ HTML ์ด๋ฉ์ผ ํ ํ๋ฆฟ ํผ ์์ ์ ์ ์์ฌํญ
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fe_growing.