Today I Learn 220428
<setAttribute()์ classList.add()์ ์ฐจ์ด>
setAttribute()๋ ๊ฑฐ์ ์ฌ์ฉํ์ง ์์
- setAttribute๋ ๋๋ฌด ๊ฐ๋ ฅํด์ ๊ฑฐ์ ์ฌ์ฉํ์ง ์์.
- ์ด๋ inline์ผ๋ก ์คํ์ผ์ ์ ์ฉํ๋ ๊ฒ์ด๋ผ CSS ํ์ผ์์ ์ ์ฉํ ์ค์ ๋ณด๋ค ์ฐ์ ์ผ๋ก ์ ์ฉ๋ฉ๋๋ค. ๋๋ฌธ์ ์ ์ฌ์ฉํ์ง ์๋๋ค!!
๋ฐ๋ผ์,
- ์ ํํ๋ setAttribute()์ classList๊ฐ ๋ค๋ฃจ๊ณ ์๋ ๋์์ ๋ฒ์๊ฐ ๋ค๋ฆ
#setAttribute()๋ HTML ์์์ inline ์คํ์ผ๋ก ์ด๋ ํ ์์ฑ์ ์ถ๊ฐํ๋ ๊ฒ
-class ์์ฑ
-style ์์ฑ
-href ์์ฑ
-....๋ฑ๋ฑ
#classList()๋ ์์์ ์ฌ๋ฌ ์์ฑ ์ค ํ๋์ธ ํด๋์ค ์์ฑ๋ง์ ๋ค๋ฃจ๋ ๊ฒ
- ์์์ ํด๋์ค๋ฅผ ์ถ๊ฐ/๋ณ๊ฒฝ/์ ๊ฑฐ ํ๋์์ผ๋ก ์์๋ฅผ ๋์ ์ผ๋ก ๋ค๋ฃจ๊ณ ์ถ๋ค๋ฉด, classList๋ฅผ ์ถ์ฒ!
์ฌ์ค ์ค๋ฌด์์๋ ๋ ๋ค ์ฌ์ฉํ์ง ์๋๋ค!
this - "์๊ธฐ์ฐธ์กฐ๋ณ์"
์ ์
- ๋ด๊ฐ ์ด๋ป๊ฒ ๋ถ๋ฆฌ๋๋์ ๋ฐ๋ผ ๋ฐ์ธ๋ฉ ๋๋ ๊ฒ.
๋ชฉ์
- "๊ฐ์ฒด"์์ "๋ด"๊ฐ ํ๋กํผํฐ๋ ๋ฉ์๋๋ฅผ ์ฐธ์กฐํ๊ธฐ ์ํด
"์ด๋์" "์ด๋ป๊ฒ" ๋ถ๋ฅด๋๋์ ๋ฐ๋ผ this๋ ๋ฌ๋ผ์ง๋ค!
- ์ผ๋ฐ ํจ์๋ก ํธ์ถ ๋์์ ๋ -> ์ ์ญ ๊ฐ์ฒด
- ํจ์() -> window
function test(){ console.log(this) } test()
Window {0: global, window: Window, self: Window, document: document, name: '', location: Location, โฆ}
- ๋ฉ์๋๋ก ํธ์ถ ๋์์ ๋ -> **"๊ทธ" ๋ฉ์๋๋ฅผ ๋ณด์ ํ ๊ฐ์ฒด **
- ๊ฐ์ฒด.๋ฉ์๋() ->๊ฐ์ฒด
const obj = {} const obj = { test : function(){ console.log(this) } } obj.test()
{test: ฦ}
test: ฦ ()
arguments: null
caller: null
length: 0
name: "test"
prototype: {constructor: ฦ}
[[FunctionLocation]]: VM4936:2
[[Prototype]]: ฦ ()
[[Scopes]]: Scopes[2]
[[Prototype]]: Object
- ์์ฑ์ ํจ์๋ก ํธ์ถ ๋์์ ๋ -> "๋ฏธ๋"์ ์์ฑ๋ "์ธ์คํด์ค" -> ๊ฐ์ฒด
Teacher {name: 'iseo'} name: "iseo" [[Prototype]]: Object constructor: ฦ Teacher(name) [[Prototype]]: Object
//cf. const person2 = Teacher('iseo') //์ด๋ ๊ฒ ๋ฃ์ผ๋ฉด(newํค์๋ ๋นผ๋จน์ผ๋ฉด) ์ผ๋ฐ ํจ์ ํธ์ถ๊ณผ ๊ฐ์์ ธ ์ ์ญ์ธ window์ Teacher : 'iseo'๊ฐ ๋ค์ด๊ฐ๋ฒ๋ฆผ.... //๊ฒฐ๋ก : ์ด ๊ฒฝ์ฐ์ this๋ window์ ๋ฐ์ธ๋ฉ ๋์ด๋ฒ๋ฆฐ๋ค!!
-
function Teacher(name){ this.name = name //"๋ฏธ๋"์ ์์ฑ๋ "์ธ์คํด์ค" } const person = new Teacher('iseo') person
- apply/call/bind๋ก "๊ฐ์ "ํธ์ถ ๋์์ ๋
์ฐธ๊ณ ํ๊ธฐ ์ข์ ๋ธ๋ก๊ทธ ๊ธ ๋งํฌ
'๐๐จ๐๐๐ฒ ๐ ๐๐๐๐ซ๐ง' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐๐จ๐๐๐ฒ ๐ ๐๐๐๐ซ๐ง 2022.05.03.ํ (0) | 2022.05.03 |
---|---|
๐๐จ๐๐๐ฒ ๐ ๐๐๐๐ซ๐ง 2022.05.02.์ (0) | 2022.05.02 |
๐๐จ๐๐๐ฒ ๐ ๐๐๐๐ซ๐ง 2022.04.27.์ (0) | 2022.05.02 |
๐๐จ๐๐๐ฒ ๐ ๐๐๐๐ซ๐ง 2022.04.25.์ (0) | 2022.04.25 |
๐๐จ๐๐๐ฒ ๐ ๐๐๐๐ซ๐ง 2022.04.22.๊ธ (0) | 2022.04.22 |
๋๊ธ