๐จ JavaScript/๊ฐ๋
[๋๋ฆผ์ฝ๋ฉ] ์ฝ๋ฐฑํจ์ (1) : ์ฝ๋ฐฑ์ง์ฅ ์์
์ฝ๋ฐฑ์ง์ฅ // ๊ธฐ๋ณธ์ธํ class UserStorage { loginUser(id, password, onSuccess, onError) { setTimeout(() => { if ( (id === 'master' && password === 'master00') || (id === 'submaster' && password === 'submaster00') ) { onSuccess(id); } else { onError(new Error('not found')); } }, 2000); } getRoles(user, onSucces, onError) { setTimeout(() => { if (user === 'master') { onSuccess({name: 'Master', role : 'admin'..
[mdn, ๋๋ฆผ์ฝ๋ฉ, ์ฝ๋ฉ์ ํ] ์ฝ๋ฐฑํจ์ (1) : ๋๊ธฐ์ ๋น๋๊ธฐ ๊ฐ๋
์ฝ๋ฐฑํจ์ ์๋ฐ์คํฌ๋ฆฝํธ๋ ๋๊ธฐ์ (synchronous) ์ธ์ด์ด๋ค. ์ด ๋ง์ ์ฝ๋๋ฅผ ์์ฑํ ์์์ ๋ง์ถฐ ๋๊ธฐ์ ์ผ๋ก ์คํ๋๋ค๋ ๋ง์ด๋ค. ์๋๋ ๋น๋๊ธฐ์ ์ผ๋ก ์คํ๋๋ ํจ์์ด๋ค. console.log('1'); setTimeout(() => console.log('2'), 1000); console.log('3'); //1 //3 //2 Synchronous callback function printImmediately(print) { print(); } printImmediately(() => console.log('hello')); Asynchronous callback function printWithdelay(print, timeout) { setTimeout(print, timeout); } printW..
[๋๋ฆผ์ฝ๋ฉ] JSON to Object (parse)
JSON to Object parse(json) const coder = { name: 'Noran', language: 'Javascript', height: null, birthDate: new Date(), sayhi: () => { console.log(`Hello, I'm ${name}!`); }, }; json = JSON.stringify(coder); const obj = JSON.parse(json); console.log(obj); //{name: 'Noran', language: 'Javascript', height: null, birthDate: '2022-07-12T03:03:18.870Z'}birthDate: "2022-07-12T03:03:18.870Z"height: nulll..
[๋๋ฆผ์ฝ๋ฉ] Object to JSON (stringify)
Object to JSON stringify(obj) stringify๋ ๋ฐ์ดํฐ๋ฅผ stringํ์ ์ผ๋ก ๋ณํํ๋ค. let json = JSON.stringify(true); console.log(json); //"true" let json = JSON.stringify(['Noran','Paran']); console.log(json); //["Noran","Paran"] ํ๊ฐ์ single quote๊ฐ ์๋ double quote๋ก ๋ฐ๋ ๊ฒ์ ๋ณผ ์ ์๋ค. ์ด๊ฒ์ด JSON์ ๊ท๊ฒฉ์ฌํญ์ด๋ค. ๋ํ ์๋์ฒ๋ผ ํจ์๋ javascript์๋ง ์์ฒด์ ์ผ๋ก ๋ค์ด์๋ ๋ฐ์ดํฐ๋ JSON์ ํฌํจ๋์ง ์๋๋ค. const coder = { name: 'Noran', language: 'Javascript', height: nu..
[๋๋ฆผ์ฝ๋ฉ] JSON์ด๋?
JSON JavaScript Object Notation JSON์ Object ๋ํ javascript์ฒ๋ผ {key: value}๋ก ์ด๋ฃจ์ด์ ธ ์๋ค. ๋ฐ์ดํฐ๋ฅผ ์ฃผ๊ณ ๋ฐ์ ๋ ์ธ ์ ์๋ ๊ฐ์ฅ ๊ฐ๋จํ format์ด๋ค. C,C++,C#,JAVA,Python,PHP ๋ฑ์ ๊ฑฐ์ ๋๋ถ๋ถ์ ์ธ์ด๋ค์ ๋ชจ๋ JSON์ผ๋ก serialization(์ง๋ ฌํ)๋ object๋ฅผ ๋ค์ ๊ทธ ์ธ์ด์ ๋ง๊ฒ object๋ก ๋ณํ ๋ฐ ๋ค์ JSON์ผ๋ก serialization(์ง๋ ฌํ)ํ ์ ์๋ค. ์ถ์ฒ : ๋๋ฆผ์ฝ๋ฉ https://www.youtube.com/@dream-coding / MDN https://developer.mozilla.org/ko
[๋๋ฆผ์ฝ๋ฉ] ์ ์ฉํ ๋ฐฐ์ด(array) api (3) : reduce, reduceRight, sort, api ๋ค์ค์ผ๋ก ์ฐ๊ธฐ
class Coder { constructor(name, age, enrolled, score) { this.name = name; this.age = age; this.enrolled = enrolled; this.score = score; } } const coders = [ new Coder('A', 29, true, 45), new Coder('B', 28, false, 80), new Coder('C', 30, true, 90), new Coder('D', 40, false, 66), new Coder('E', 18, true, 88), ] reduce ๋ฐฐ์ด์ ๊ฐ ๋ฐ์ดํฐ์ ์ฃผ์ด์ง ๋ฆฌ๋์(reducer)ํจ์๋ฅผ ์คํํ๊ณ , ํ๋์ ๊ฒฐ๊ณผ๊ฐ์ ๋ฐํํ๋ค. ๋ฆฌ๋์ ์ฝ๋ฐฑํจ์๋ ๋ค ๊ฐ์ ์ธ์๋ฅผ ๊ฐ์ง๋ค. ๋์ฐ๊ธฐ(..