본문 바로가기

JavaScript14

회원가입 register js JS에서 Json의 AJAX요청을 하기 위해서 jqeury를 추가한다 html css js 가 응답되었을때 window.onload class RegisterApi를 만들되 싱글톤으로 만들어준다 class RegisterApi { static #instance = null; static getInstance() { if(this.#instance == null) { this.#instance = new RegisterApi(); } return this.#instance; } register(user) { $.ajax({ async: false, type: "post", url: "/api/account/register", contentType: "application/json", data: JSON.s.. 2023. 5. 3.
자바스크립트 기본 //함수선언 function doSomething(add){ console.log(add); const result = add(2 , 3); console.log(result); } function add(a,b){ const sum = a + b; return sum; } //함수 호출 doSomething(add); //add함수 자체를 파라메터 값으로 넘김 //doSomething(add()); add()함수 자체가 먼저 실행되고 sum 값이 doSomething의 파라메터값으로 들어가서 출력 그러나 sum에 숫자가 없으므로 NaN으로 출력됨 const result = add(1,2); console.log(result); 2022. 5. 19.
JavaScript await and Promise APIs //async & await // clear style of using promise :) // 1. async async function fetchUser(){ // do network request in 10secs... return 'son'; } const user = fetchUser(); user.then(console.log); console.log(user); //2. await function delay(ms) { return new Promise(resolve => setTimeout(resolve. ms)) } async function getApple() { await delay(3000); return 'a'; } function getBanana(){ return delay(30.. 2022. 5. 16.
JavaScript Promise 'use strict' const { reject } = require("async") // promise is a JavaScript object for asynchronous operation // State: pending -> fulfilled or rejected //Producer vs Consumer //1.Producer // when new Promise is created, the ececutor runs automatically const promise = new Promise((resolve, reject) => { // doing some heavy work (network, read, files) console.log('doing something...'); setTimeout(.. 2022. 5. 9.