본문 바로가기

프로그래밍 언어/JavaScript25

webpack webpack 실행 npm init -y npm i webpack webpack-cli -D (--save-dev) 배포용 > 빌드할떄 빠지게 된다. npm i lodashlodash > dependency에 추가 되어있음 스크립트로 설정하기 "webpack --mode=none --entry=src/index.js --output-public/ouput.js"이런식으로 옵션 줄 수 있다. 근데 넘길어 그래서 webpack.config.js 설정파일에 쓴다. // webpack.config.js // `webpack` command will pick up this config setup by default var path = require('path'); //노드 path 라이브러리 mod.. 2021. 7. 16.
map, filter, reduce map, filter, reduce const products = [ {name: '안녕', price: 12000}, {name: '하세요', price: 15000}, {name: '저는', price: 20000}, {name: '지니', price: 25000}, {name: '입니다', price: 15000} ]; map map 로직 const map = (f, iter) => {//f 라는 함수를 받아서 어떤값을 수집할 것인지 위임한다.(추상화) let res = []; for (const a of iter) { res.push(f(a)); } return res; }; 고차함수이다. /////////////es5 /////////////// let names = []; for (const .. 2021. 7. 5.
ES6 이터러블 /이터레이터, 리스트 순회 리스트 순회 기존 for(var i =0;i< str.length;i++){ ... } es6 for(const a of list){ ... } 간결하게 변경 되었음 이터러블/이터레이터 Array , Set, Map const arr = [1,2,3]; for(const a of arr){ } const set = new Set([1,2,3]); for(const a of set){ } const map = new Map(['a',1], ['b',2] , ['c',3]); for(const a of map){ } array 는 arr[0] , arr[1] 이렇게 해서 값을 찾을 수 있지만 Set과 Map은 불가능함 어떻게 for of문에서 동작이 되는가? Symbol.iterator es6에 추가된 sy.. 2021. 7. 3.
promise / async await promise 자바스크립트 비동기 처리에 사용되는 객체 보통 서버에서 받아온 데이터를 화면에 표시할 때 사용 function getData(callback){ return new Promise(function(resolve,reject)){ axios.post(&#39;~~&#39;, param) .catch(function (err) { }).then(function (rs) { resolve(response); }); } } getData().then(function(data){ console.log(data); });프로미스 상태(states) Pending(대기) : 비동기 로직이 완료 x new Promise(); 메서드 호출 할 때 Fulfilled(이행) : 비동기 처리 완료되어 프로미스가 .. 2021. 6. 29.
반응형