본문 바로가기
728x90
반응형

js20

Truthy and Falsy 트루디 하다 펄스디 하다 ₩₩₩javascript //falsy 한것 console.log(!undifined); // true console.log(!null); // true console.log(!0); // true console.log(!''); // true console.log(!NaN); // true //그 외는 truthy const value = 1/ 'asdf'; console.log(value); //NaN console.log(!3); //false console.log(!'hello'); //false console.log(!['apple']); //false₩₩₩ 2021. 4. 23.
class - food class 만들기 class ₩₩₩javascript class Food{ constructor(name){ this.name = name; this.brands=[]; } addBrands(brand){ this.brands.push(brand) } print(){ console.log(`${this.name}을/를 파는 음식점들`) console.log(this.brands.join(`, `)); } } const pizza = new Food('피자'); pizza.addBrand('피자헛'); pazza.addBrand('도미노 피자'); const chiken = new Food('피자'); chicken.addBrand('굽네치킨'); ch.. 2021. 4. 22.
async - await async - await async & await는 자바스크립트의 비동기 처리 패턴이며 기존의 비동기 처리방식인 콜백함수와 프로미스의 단점을 보완하고 개발자가 읽기 좋은 코드를 작성할수있다 //Promise객체를 리턴하는 함수 function p(ms){ return new Promise((resolve, reject)=>{ setTimeout(() => { resolve(ms); }, ms); }); } //로직 수행 p(1000).then(ms=>{ console.log(`${ms} ms 후에 실행된다.`) }); //프로미스객체를 리턴하는 함수를 await로 호출하는 방법 //비동기 처리가 끝날때까지 기다렸다가 (async function main() { const ms = await p(1000).. 2021. 4. 8.
promise 프로미스 Promise는 호출을 하면서 끝나는 동안에도 실행이 되는 비동기 방식 함수 사용법 /* executor 함수는 resolve 와 reject 를 파라미터로 갖는다. (resolve, reject) => {...0} resolve와 reject 는 함수 resolve(), reject() */ new Promise(/* executor */(resolve, reject)=>{}); //생성자를 통해 프로미스 객체를 만드는순간 pending(대기)상태라고 한다. new Promise((resolve, reject)=>{}); //pending //executor 함수 파라미터중 하나인 resolve 함수를 실행하면, fulfilled(이행) 상태가 된다. new Promise((resolve, r.. 2021. 4. 7.
객체의 부모 노드에 접근, 자식노드에 접근 $('a[class="on"]').parent('li').parent('ul').addClass("in").parent().children('a').addClass("on"); a태그에 on이 있는 부모객체 li 의 부모객체 ul 에 in을 추가하고 부모노드에서 a에 on 클래스를 추가 2021. 3. 31.
클릭한 버튼의 id값 확인 function addFavoMain(val){ console.log(val); } 2021. 3. 25.
728x90
반응형