๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๋ฐ˜์‘ํ˜•

๐Ÿ“’ JavaScript29

[JS Tam9์ƒํ™œ] #3 ๊ฐ์ฒด์™€ ํ”„๋กœํผํ‹ฐ ๐Ÿ“ŒObject ๊ฐ์ฒด ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” ๊ฐ์ฒด(object) ๊ธฐ๋ฐ˜์˜ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด ๊ฐ์ฒด๋Š” mutable (๋ณ€๊ฒฝ ๊ฐ€๋Šฅํ•œ ๊ฐ’) ์ด๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ ๊ฑฐ์˜ ๋ชจ๋“ ๊ฒƒ์ด ๊ฐ์ฒด์ด๋ฏ€๋กœ ๋ณ€๊ฒฝ์ด ๊ฐ€๋Šฅํ•˜๋‹ค. ๊ฐ์ฒด๋Š” property๋กœ ๊ตฌ์„ฑ๋œ๋‹ค JS์˜ ํ•จ์ˆ˜๋„ ๊ฐ์ฒด๋กœ ์ทจ๊ธ‰ : ํ•จ์ˆ˜ = property ํ”„๋กœํผํ‹ฐ : ๊ฐ์ฒด์˜ ์ƒํƒœ๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๊ฐ’(data) ๋ฉ”์„œ๋“œ: ํ”„๋กœํผํ‹ฐ๋ฅผ ์ฐธ์กฐํ•˜๊ณ  ์กฐ์ž‘ํ•˜๋Š” ๋™์ž‘ property๊ฐ’์ด ํ•จ์ˆ˜์ธ ๊ฒฝ์šฐ ๊ฐ์ฒด์— ๋ฌถ์—ฌ์žˆ๋Š” ํ•จ์ˆ˜ ex) increase : ๋ฉ”์„œ๋“œ num :ํ”„๋กœํผํ‹ฐ var counter = { num : 0, increase : function(){ this.num++ } }; immutable ๋ณ€๊ฒฝ ๋ถˆ๊ฐ€๋Šฅํ•œ ๊ฐ’ const ๋ณ€์ˆ˜, Object.freeze ๊ฐ์ฒด mutable ๋ณ€๊ฒฝ ๊ฐ€๋Šฅํ•œ ๊ฐ’ ๊ฐ์ฒด,ํ•จ์ˆ˜,๋ฐฐ์—ด,.. 2021. 7. 17.
[JS Tam9์ƒํ™œ] #2 FE ์ƒํƒœ๊ด€๋ฆฌ ํ”„๋ก ํŠธ์—”๋“œ์˜ ์ƒํƒœ๊ด€๋ฆฌ ํ”„๋ก ํŠธ์—”๋“œ๋ฅผ ๊ฐœ๋ฐœํ•˜๋ฉด์„œ ๋Š๋ผ๋Š” ๋งˆ์ฃผํ•˜๋Š” ์–ด๋ ค์›€ ์ค‘ ํ•˜๋‚˜๋Š” ์ƒํƒœ state๊ด€๋ฆฌ FE์˜ ์ƒํƒœ๋Š” ์›น ์ƒ์˜ ๋‹ค์–‘ํ•œ ์š”์†Œ๋“ค์ด ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๊ฐ’์„ ๋งํ•˜๋ฉฐ ์ด ๊ฐ’๋“ค์€ ์‚ฌ์šฉ์ž์˜ ์„ ํƒ๊ณผ ๋ฐฉํ–ฅ์— ๋”ฐ๋ผ ๋ณ€ํ™”ํ•œ๋‹ค. ์ด ์ƒํƒœ๋ฅผ ์–ด๋–ป๊ฒŒ ๊ด€๋ฆฌํ•˜๊ณ  ์ œ์–ดํ•˜๋Š๋ƒ์— ๋”ฐ๋ผ ์ฝ”๋“œ์˜ ์ผ๊ด€์„ฑ์ด ๊ฒฐ์ •๋˜๋Š”๋ฐ, ํ”„๋ก ํŠธ์—”๋“œ์˜ ์ƒํƒœ๊ด€๋ฆฌ๋Š” ํ•œ ๊ณณ์—์„œ ํ•˜๋ฉด ๊ฐ€์žฅ ์ข‹๋‹ค. ๋ณดํ†ต์€ ์ตœ์ƒ์œ„ component ๋‚˜ storage์— ๋ณด๊ด€ํ•œ๋‹ค. ๊ทธ๋ ‡๋‹ค๋ฉด ์„ค๊ณ„๋Š” ? ๋ณดํ†ต ์•„๋ž˜์™€ ๊ฐ™์ด component๋ฅผ ๊ตฌ์„ฑํ•˜์—ฌ ๋ถ€๋ชจ๊ฐ€ state๋ฅผ ๊ด€๋ฆฌํ•˜๋ฉฐ ์ƒํƒœ ๋ณ€ํ™”์— ๋”ฐ๋ผ ์ž์‹ component๋Š” rendering๋งŒ ํ•ด์ฃผ๋Š” ๊ตฌ์กฐ๋กœ ์„ค๊ณ„ํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค. ๋ถ€๋ชจ component : ์ƒํƒœ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์•Š์Œ ์ž์‹ component : ์ƒํƒœ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์ง€ ์•Š์Œ ex ) Tod.. 2021. 7. 16.
[JS Tam9์ƒํ™œ] #1 DOM DOM ( Document Object Model) : ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋กœ DOM ๊ตฌ์กฐ์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋„๋ก ๋ฐฉ๋ฒ•์„ ์ œ๊ณตํ•˜์—ฌ ๊ตฌ์กฐ ๋‚˜ ์Šคํƒ€์ผ์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋•๋Š” ์ธํ„ฐํŽ˜์ด์Šค. ์ฐธ๊ณ  : https://developer.mozilla.org/ko/docs/Web/API/Document_Object_Model/Introduction - HTML, XML ๋ฌธ์„œ์˜ ํ”„๋กœ๊ทธ๋ž˜๋ฐ interface - ๋ฌธ์„œ์˜ ๊ตฌ์กฐํ™”๋œ ํ‘œํ˜„์„ ์ œ๊ณต - ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๊ฐ€ DOM์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ• ์ œ๊ณต DOM์„ ์ฐพ๋Š” ๋ฐฉ๋ฒ• ์•„๋ž˜ ๋ฉ”์„œ๋“œ๋ฅผ ํ†ตํ•ด์„œ getElement getElements querySelector querySelectorAll getElement document.getElementsByTagName('div’) document.. 2021. 7. 16.
[JavaScript] Closure ๊ณผ Currying Closure closure ์˜ ์žฅ์  ํ™œ์šฉ ๊ฐ’์„ ๊ฐ€์ง„ ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Œ function sum(a,b) { return a+b; } function calculate(fn, prev) { return (v) =>{ return fn(prev,v); } const sum100 = calculate(sum, 100) sum100(20); //120 โ– sum100 sum100 = (v) => { return sum(100,v) } sum100์ด๋ผ๋Š” ํ•จ์ˆ˜๋Š” ์–ด๋–ป๊ฒŒ ๋ณด๋ฉด 100์ด๋ผ๋Š” ๊ฐ’์„ ๊ฐ€์ง„ ํ•จ์ˆ˜๊ฐ€ ๋˜๋Š” ๊ฒƒ์ด๋‹ค. ํฌ๋กฌ ๋””๋ฒ„๊ฑฐ์—์„œ Scope(์œ ํšจ๋ฒ”์œ„) ๋ฅผ ํ™•์ธํ•ด๋ณด๋ฉด Closure : { prev :100, fn: f } Currying ๊ฐ’์„ ๊ฐ€์ง„ ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ํ•จ์ˆ˜ ex) calculate ํ•จ์ˆ˜ ํ•จ์ˆ˜.. 2021. 4. 9.
javascript ๊ณผ Promise ์™€ async await ์›๋ณธ ์ฝ”๋“œ (callback ์ง€์˜ฅ์— ๋น ์งˆ๋ž‘ ๋ง๋ž‘) url์˜ json ๋ฐ์ดํ„ฐ์™€ json ์ค‘ title ๋ฐ์ดํ„ฐ๋ฅผ ๋น„๋™๊ธฐ์ ์œผ๋กœ ์ถœ๋ ฅ์‹œํ‚ค๋Š” code 1์ดˆ ํ›„ json ์ถœ๋ ฅ ๊ทธ๋กœ๋ถ€ํ„ฐ 2์ดˆ ํ›„ json.title ์ถœ๋ ฅ fetch('https://jsonplaceholder.typicode.com/todos/1') .then(response => response.json()) .then( (json)=> { setTimeout(() => { console.log(json); setTimeout( () => { console.log(json.title); },2000); },1000); }) ์ฝœ๋ฐฑ ํ•จ์ˆ˜ ๋ถ„๋ฆฌ์™€ then ์‚ฌ์šฉ Promise๋ฅผ ์‚ฌ์šฉํ•ด๋ณด์ž const delay = (data,ms) =>new Promise(.. 2021. 3. 15.
[Javascript] Prototype ์„ ํ†ตํ•œ ์ƒ์† ๊ณผ __proto__ +(MDN ์˜ˆ์ œ๋กœ ๋ณด๋Š” Prototype ์ƒ์†) ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ class๋ž€? ์ƒ์„ฑ์žํ•จ์ˆ˜ ์ƒ์„ฑ ํ•จ์ˆ˜ ํ˜ธ์ถœ ๊ฐ์ฒด ์ƒ์„ฑ ์‹œ ๋‚ด๋ถ€ ๊ตฌํ˜„ ํฌ๋กฑ์˜ ์ˆ˜์—…๊ณผ ์ƒํ™œ์ฝ”๋”ฉ js ๊ฐ์ฒด์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ์ฐธ์กฐํ•˜์—ฌ MDN์— ์ž‡๋Š” Class Model ์ƒ์†์˜ˆ์ œ -> Constructor function ๊ณผ prototype์„ ์ด์šฉํ•˜์—ฌ ์ƒ์†์„ ๊ตฌํ˜„ํ•ด ๋ณด์•˜๋‹ค. Class ๋ฅผ ์ด์šฉํ•œ ์ƒ์† Javascript๋Š” ํ”„๋กœํ† ํƒ€์ž… based ์–ธ์–ด ์›๋ž˜๋Š” class ๊ฐ€ ์žˆ๊ธฐ ์ „์— ์ƒ์„ฑ์ž ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ ์ƒ์†์„ ๊ตฌํ˜„ํ–ˆ๋‹ค. ๋”ฐ๋ผ์„œ Class ์˜ extends ๋ฅผ ํ”„๋กœํ† ํƒ€์ž…์„ ํ†ตํ•ด ๊ตฌํ˜„ํ•ด๋ณด์ž Constructor function (์ƒ์„ฑ์ž ํ•จ์ˆ˜) ๋ฐ ๊ฐ์ฒด ์ƒ์„ฑ 1) Car (๋ถ€๋ชจ) , Model (์ž์‹) ์ด๋ผ๋Š” ์ƒ์„ฑ์ž ํ•จ์ˆ˜ ์ƒ์„ฑ ๊ฐ์ž์˜ Prototype ๊ฐ์ฒด๊ฐ€ ์ƒ์„ฑ๋จ ( Car's prototype ,.. 2021. 3. 12.
[JavaScript ] prototype vs __proto__ + ๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ํ•จ์ˆ˜๋Š” ๊ฐ์ฒด function Person(){} var Person = new Function(); ๊ฐ์ฒด์ด๊ธฐ ๋•Œ๋ฌธ์— property๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Œ ↓ ํ•จ๊ป˜ ์ดํ•ดํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š” https://rrecoder.tistory.com/87?category=947948 JavaScript ํ”„๋กœํ† ํƒ€์ž…(prototype) ์ดํ•ด Object (๊ฐ์ฒด) ์„œ๋กœ ์—ฐ๊ด€๋œ ๋ณ€์ˆ˜์™€ ํ•จ์ˆ˜๋ฅผ ๊ทธ๋ฃนํ•‘ํ•ด์„œ ์ด๋ฆ„์„ ๋ถ™์ธ ๊ฒƒ var memberObject = { tami: 'name', developer: 'java', age:'25', } this ๋ฉ”์„œ๋“œ๊ฐ€ ์ž์‹ ์ด ์†ํ•ด์žˆ๋Š” ๊ฐ์ฒด๋ฅผ ๊ฐ€๋ฆฌํ‚ค๋Š” ํ‚ค์›Œ๋“œ ๊ฐ์ฒด๊ฐ€ ๋‚ด๋ถ€์ .. rrecoder.tistory.com prototype ๊ณผ __proto__ ์˜ˆ์‹œ) Person Person.p.. 2021. 3. 11.
[Javascript] __proto__ ์™€ ์ƒ์† โ–บ Object(๊ฐ์ฒด)์—์„œ์˜ ์ƒ์† ๋ณดํ†ต์€ class ๋‹จ๊ณ„์—์„œ ์ƒ์†์„ ๋ฐ›๊ณ  ์ƒ์†์„ ๋ฐ›์€ class ๊ฐ€ object๋ฅผ ๋งŒ๋“ค์ง€๋งŒ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ๋Š” ๊ฐ์ฒด ์ž์ฒด๋ฅผ ์ƒ์†๋ฐ›์„ ์ˆ˜ ์žˆ์Œ prototype link : ๊ฐ์ฒด์˜ ์ƒ์†์„ ์—ฐ๊ฒฐํ•ด์ฃผ๋Š” ๋งํฌ prototype object : sub object๊ฐ€ ์ƒ์†์„ ๋ฐ›์€ ๊ฐ์ฒด ์ถœ์ฒ˜)opentutorials.org/module/4047/24626 ๊ฐ์ฒด์™€ ๊ฐ์ฒด ์ƒ์† ์‹คํ–‰๋˜๋Š” __proto__ ์˜ˆ์ œ1) var superObj = {superVal:'super'} var subObj = {subVal :'sub'} subObj.__proto__ = superObj; console.log("subVal",subObj.subVal); //sub console.log("superVal",.. 2021. 3. 11.
JavaScript ํ•จ์ˆ˜ํ˜ธ์ถœ Call / Bind ๋ฉ”์„œ๋“œ ์ฒ˜์Œ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋ฐฐ์šธ ๋• ์“ฐ๋ผ๋Š”๋Œ€๋กœ ํ•จ์ˆ˜๋ฅผ ์“ฐ๊ณ  this ๋„ ๊ทธ๋ƒฅ์ผ์ง€๋งŒ, ๋ช‡๊ฐœ์˜ ํ”„๋กœ์ ํŠธ๋ฅผ ๊ฒฝํ—˜ํ•˜๊ณ  ๋‚˜์„œ ๋‹ค์‹œ ๊ณต๋ถ€ํ•ด๋ณด๋Š” JS๋Š” ์ •๋ง ์‹ ๊ธฐํ•˜๊ณ  ์žฌ๋ฐŒ๋Š” ๋„๊ตฌ์ด๊ตฌ๋‚˜ .! ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ํ•จ์ˆ˜ JS์˜ ํ•จ์ˆ˜ : ์ž์‹ ๋งŒ์˜ this๋ฅผ ์ •์˜ํ•˜๋Š”๊ฒƒ ์˜ˆ์‹œ๋กœ sayHello ๋ผ๋Š” ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค๊ณ  this๋ฅผ ์‹คํ–‰์‹œํ‚ค๋ฉด Window ๊ฐ์ฒด๊ฐ€ ๋‚˜์˜จ๋‹ค. ์ฆ‰ JS์—์„œ ๊ธฐ๋ณธ์ ์ธ this = windowr๊ฐ์ฒด ๋ผ๋Š”๊ฒƒ ๋‚˜๋Š” sayHello์—์„œ window๋ฅผ ์“ฐ๊ณ ์‹ถ์ง€ ์•Š๋‹ค. this๋ฅผ ๊ทธ๋•Œ๊ทธ๋•Œ ์•Œ๋งž์€ ๊ฐ์ฒด๋กœ ๋ฐ”๊ฟ”์•ผ ํ•˜๋Š”๋ฐ ์ด๊ฒƒ์ด ๋ฐ”๋กœ this์˜ binding! this๋ฅผ ์•Œ๋งž๊ฒŒ ๋ฐ”๊ฟ”์ฃผ๋Š” ํ•จ์ˆ˜๊ฐ€ ์žˆ๋Š”๋ฐ ๊ทธ๊ฒƒ์ด ๋ฐ”๋กœ call apply, bind์ด๋‹ค . ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ๋Š” ํ•จ์ˆ˜๋ฅผ ๋งŽ์ด ๋‹ค๋ฃจ๊ณ  this๋ฅผ ๋‹ค๋ค„์•ผ ํ•  ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์Œ!! ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ.. 2021. 3. 11.
๋ฐ˜์‘ํ˜•