목록vaniilaJS (4)
바르고 뜨겁게
JavaScript - dot(.) 점이 있는 JSON parsing Object : {gcm.notification.body: "테스트 메시지", gcm.notification.title: "테스트 타이틀"} 위와 같은 형태의 JSON 은 Object.gcm.notification.body 형태로 파싱하면 에러가 난다.Object.['gcm.notification.body'] 이렇게 파싱해야 에러없이 원하는 값을 얻을 수 있다.
setInterval 사용시 func.apply is not a function 에러자바스크립트에서는 함수 호출 자리에 함수의 이름이 아니라 함수명() 처럼 코딩시 정의된 함수가 즉시 호출되어 버린다.따라서 아래와 같이 코딩하면 func.apply is not a function 에러를 만나게 된다. 잘못된 사용법_myFunc = () => { ... } this._timerId = setInterval(this.myFunc(),1000);코드 실행시 즉시 1번 호출이 되고, 10초 뒤엔 func.apply is not a function 에러를 만나게 된다.의도는 myFunc() 함수를 10초마다 호출하여 실행하는 것이지만, 해결 방법_myFunc = () => { ... } this._time..
Vanilla JS - Array.includes배열안에 특정 argument가 포함되어 있는지 검사한다. const numbers = [153, 8, 45, 68, 4153, 5, 8541, 635, 153, 3, 5, 1, 85, 1, 3, 5, 85]; if(numbers.includes(153)){ console.log('153 존재'); }else{ numbers.push(153); // 배열에 추가함 } 153 존재
오브젝트에서 변수꺼내기 (비구조화 할당 Object Destructuring)1. 변수명 변경해서 꺼내기2. 오브젝트 변수명으로 받3. 배열 형태로 꺼내기 const obj = { depth1_0: "1단계 0", depth1_1: "1단계 1", depth1_2: { depth2_0: "2단계 0", depth2_1: "2단계 1" } } // 기존방식 const oldDepth1 = obj.depth1_0; const oldDepth2 = obj.depth1_2.depth2_0; console.log(`기존방식 oldDepth1: ${oldDepth1} / oldDepth2: ${oldDepth2}`); // (비구조화 할당 Object Destructuring) // 변수명변경 , 그대로..