본문 바로가기

JS

TSLint TSLint는 타입스크립트 소스 코드가 코딩 규칙을 따라 컴파일된다면, 타입스크립트의 코드 질 확인을 위한 소프트웨어 개발에 쓰이는 정적 코드 분석 도구이다. TSLint는 타입스크립트 코드의 가독성, 유지보수성, 기능성 오류를 검사한다. 사용법tslint [options] [file ...] 기본적으로, TSLint는 파일이 lint될 파일의 디렉토리에서 tslint.json이라는 configuration 파일을 찾는다. 못찾으면 상위 디렉토리를 검색한다. --fix대부분의 경고를 자동 수정https://stackoverflow.com/questions/44841215/auto-fix-tslint-warnings -c, --configtslint 어떤 규칙이 활성화되고 무슨 옵션이 규칙에 제공될 지 결..
암묵적 타이핑 implicit typing 변수 또는 함수 초기화 시 할당을 해준 경우 자료형을 명시하지 않아도 타이핑이 된다. let a = 10a = 'hi' a에 10을 할당하게 되면 a의 타입은 number가 된다.이렇게 쓰면 number 형식에 'hi'를 할당할 수 없다고 에러 메시지가 뜬다. let aa = 10a = 'hi'a를 선언하고 다음 줄에서 할당하게 되면 에러가 안뜬다. 선언 시 값을 할당해줘야 암묵적 타이핑이 된다. 함수의 경우도 마찬가지로function func(){ return 'hi'} let f = func()f = 10f에 함수가 할당되었으면 f는 string 타입이 된다. 그러므로 문자열은 다시 할당될 수 있지만 number 타입은 안된다. 그리고 화살표 함수나 함수를 할당해도 안된다(???) 선언 시 값을 할당..
간단한 자동차 클래스를 상속 받은 클래스로 만든 인스턴스 class Car{ speed : number; constructor(speed:number){ this.speed = speed; } originName(){ return 'Lamborghini' }} class Lambo extends Car{ speed : number; spec(speed:number,name?:string,zero100?:number){ let carName = super.originName() /*console.log(`${this.speed},${carName}`) console.log(speed,name) console.log(typeof(speed),typeof(carName),typeof(name))*/ let sec=0; let interval = setInterval..
bind() 객체로부터 메서드를 추출하고 나중에 그 메서드를 호출하고 객체의 this를 사용하길 예상한다. 그러나 객체는 사라진다. 함수로부터 바운딩 함수를 생성하면, 문제를 해결할 수 있다. 12345678910111213 this.x = 9; // this refers to global "window" object here in the browser var module = { x: 81, getX: function() { return this.x; } }; console.log(module.getX()); // 81 var retrieveX = module.getX; console.log('without binding',retrieveX()); var boundGetX = retrieveX.bind(module)..
타입스크립트 튜토리얼 모듈 모듈은 타입스크립트로 작성된 코드를 구성하기 위한 아이디어로 설계되었다. 모듈은 내부 모듈, 외부 모듈로 나뉜다. 내부 모듈 클래스, 인터페이스, 함수를 하나의 단위로 논리적으로 그룹화하기 위해 쓰이고 다른 모듈로 export될 수 있다. 이 논리적 그룹핑은 타입스크립트의 최신 버전에서 네임스페이스라고 불린다. 그래서 내부 모듈은 구식이고 네임스페이스를 대신 쓸 수 있다. 내부 모듈은 여전히 지원되지만 네임스페이스를 쓰는 게 권장된다. 내부 모듈 문법 (old)module TutorialPoint { export function add(x, y) { console.log(x+y); } } 네임스페이스 문법 (new)namespace TutorialPoint { export function add(x, y..
ECMAScript6 온라인 실행 환경 https://es6console.com/
프로미스 promise 프로미스는 비동기 처리에 사용되는 객체이다. 다른 코드의 실행이 완료될 때까지 기다리지 않고 다른 코드를 실행하는 것이다. promise를 쓰는 이유코드를 깔끔하게 하고 콜백 지옥을 방지한다. 한번 쭉 보고 넘어가면 된다.new Promise(function(resolve, reject){ setTimeout(function() { resolve(1); }, 2000); }) .then(function(result) { console.log(result); // 1 return result + 10; }) .then(function(result) { console.log(result); // 11 return result + 20; }) .then(function(result) { console.log(..
이터러블 프로토콜 iterable protocol const Iterator = (arr)=>{ let i = 0 return{ next:()=>{ return i