본문 바로가기

기타/Javascript21

WindowTimers https://developer.mozilla.org/ko/docs/Web/API/WindowTimers WindowTimers.clearInterval()WindowTimers.setInterval()를 사용하여 반복되는 실행 세트를 취소합니다.WindowTimers.clearTimeout() WindowTimers.setTimeout()를 사용하여 지연된 실행 세트를 취소합니다.WindowTimers.setInterval()주어진 1000분의1초 단위의 시간이 경과할 때마다 실행할 함수를 예약합니다.WindowTimers.setTimeout()지정된 시간 내에 실행할 함수를 예약합니다.-> 타이머가 만료된후 실행된다. 2018. 7. 27.
Array filter https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/filterhttps://www.w3schools.com/jsref/jsref_filter.asphttps://msdn.microsoft.com/ko-kr/library/ff679973(v=vs.94).aspx 배열에서 필터를 통해서 원하는 값을 찾음var users = [ {id:1,name:'a'}, {id:2,name:'b'}, {id:3,name:'c'}] const id = 1; users = users.filter((user) => { if(user.id === id){ return true; } });결과값으로는 [ { id: 1, name: .. 2018. 7. 10.
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. Mocha테스트 코드 작성중Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. Timeout 추가로 해결https://mochajs.org/#timeouts describe('a suite of tests', function() { this.timeout(500); it('should take less than 500ms', function(done){ setTimeout(done, 300); }); it('should take less than 500ms as well', function(done){ setTimeout.. 2018. 7. 5.
NPM NPM명령어 Package.json 생성npm initnpm init -y-y 를 붙일경우 default정보를 가지고 package.json생성패키지 설치 및 업데이트npm install [패키지명] 단축명령npm i [패키지명] --save의 경우 로컬인스톨됨node_modules에 다운로드되어있음 전역(global) 설치 vs 지역(local) 설치npm install [패키지명] - g- 글로벌은 system레벨에서 설치 모든곳에서 접근가능 requrire 의 경우 로컬로 가져옴 install --save , --save-dev의 차이--save 앱이 구동하기 위해 필요한 모듈&라이브러리 --save-dev는 앱 개발시에 필요한 모듈&라이브러리 (유틸리티성) dependenciesdevDepende.. 2018. 6. 19.
알파벳 증가 // alphabet increment 알파벳 증가기본 : 아스키 코드를 이용하여 증가시킴 - charCodeAt : 문자열을 아스키 코드로 변환 - fromCharCode : 아스키코드를 문자열을 구성 https://stackoverflow.com/questions/12504042/what-is-a-method-that-can-be-used-to-increment-lettersString.fromCharCode('A'.charCodeAt() + 1) // Returns B function nextChar(c) { var u = c.toUpperCase(); if (same(u,'Z')){ var txt = ''; var i = u.length; while (i--) { txt += 'A'; } return (txt+'A'); } else {.. 2018. 5. 31.
Modules Modules- 자바스크립트 모듈 로더 라이브러리(AMD, commonJS)기능을 js 언어 자체에서 지원한다.- 호출되기 전까지는 코드 실행과 동작을 하지 않는다. 파일을 나눈다고 해도 변수의 스코프가 나눠지지 않는다. //libs/math.jsexport function sum(a,b){return a+b;}export var pi = 3.141592; // app.jsimport {sum} form 'libs/math.js';sum(5,6); 2018. 5. 29.
Enhanced Object Literals Enhanced Object Literals - 향상된 객체 리터럴https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Operators/Object_initializer 속성 메서드의 축약//ES5var calc = {sum : function(){console.log("sum");}} //ES6- 괄호 하나만으로 속성 메서드 함수의 역할을 할 수있다.var calc = {sum(){console.log("sum");}}calc.sum() //바벨로 변환시https://babeljs.io/repl/var calc = { sum: function sum() { console.log("sum"); }};해당형태로 나오게된다. 속성명의 축약- 속성명.. 2018. 5. 29.
ArrowFunction Arrow Function - 화살표함수https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Functions/%EC%95%A0%EB%A1%9C%EC%9A%B0_%ED%8E%91%EC%85%98 - function이라는 키워드를 =>로 대체 (글자수의 단축)- 콜백문법의 간결화 ES5var sum = function(a,b){return a+b;}ES6var sum = (a,b) => {return a+b;} ---예시 var materials = [ 'Hydrogen', 'Helium', 'Lithium', 'Beryllium']; console.log(materials.map(material => material.length)); > Arra.. 2018. 5. 29.
Scope, Hoisting ES5는 {}에 상관없이 스코프가 설정된다 var sum = 0;for (var i = 1; i 코드는 라인 순서와 관계없이 함수선언식과 변수를 위한 메모리 공간을 먼저 확보한다. function a() 와 var는 코드의 최상단으로 끌어올려진 것(hoisted)처럼 보인다. function willBeOveridden(){return 10;}willBeOveridden() ; //5function willbeOveridden(){return 5;} .. 2018. 5. 28.