본문 바로가기

분류 전체보기

(123)
Interface Interface = object 에 대한 타입 여러 개의 함수와 여러 개의 변수 등이 구조적으로 어떻게 결합되어야 하는지에 대한 약속 하나의 함수가 가져야 할 구조에 대한 약속 interface Person { name: string; age?: number; // optional move(): void; } var person: Person= { name: "John", move: () => { } }; var person2: Person = { name: "John", age: 42, move: () => { } } var person3: Person = { name: "John:, age: true } // Interfaces can also describe a function type inter..
오브젝트 (Object) OOP에서 다루는 오브젝트와 js/ts에서의 오브젝트는 살짝 다른 개념 오히려 python의 dict, java의 map과 유사 여러 변수(혹은 함수)가 하나로 구조화된 형태 var emptyObject = {}; var personObject = { firstName : "John", lastName : "Smith" } 안에 있는 변수 하나하나를 member 혹은 property라고 한다 Adding member var personObject = { firstName : "John", lastName : "Smith" } personObject["salary"] = 14000; for (var member in personObject) { if (personObject.hasOwnProperty(me..
반복문 (Loops) 비슷한 일을 여러 번 수행 collection example var myArray: string[] = ["A", "B", "C"]; for (var i = 0; i " + myArray[i]); } break, continue var i = 10; while (true) { console.log(i + " left"); i -= 1; if (i == 0) { break; } } for (var i = 0; i < 10; i++) { if (i % 2 == 0) { continue; } console.log(i + " is an odd number.") }
조건문 (conditions) 특정 조건이 맞을 때만 일을 수행 ~하면, if var homeworkDone: boolean = true; // If 괄호 안에는 참 혹은 거짓 표현만 올 수 있음. // == 는 같은지 다른지를 표현 if (homeworkDone == true) { alert('Then you can play from now.'); } var age: number = 15; if (age > 20) { // 나이가 20살보다 많다면, 어른으로 표현 alert('You are an adult.'); } else { // 그렇지 않다면, 어른이 아닌 것으로 표현 alert('You are not an adult.'); } var kor: number = 60; var eng: number = 80; // 두 개 이상의 ..
function concept function = action 해야 할 일을 적어놓고 (definition) 그 일을 수행 (call) 함수 선언식 // The simplest function function sayHello() { alert('hello'); } sayHello(); 함수의 입력/출력 function sayMyName(name: string) { alert('name: ' + name); console.log('function sayMyName was called'); } sayMyName('a student studying typescript'); function addTwoNumber(a: number, b: number) { return a + b; } addTwoNumber(2, 3); // Nothing h..
형 변환 묵시적 형변환 // number to string var tmp = 100; tmp = tmp + ""; alert(typeof tmp);// string // string to number var tmp = "100"; tmp = tmp * 1; alert(typeof tmp);// number 명시적 형변환 Number(), String() // number to string var tmp = 100; alert(typeof tmp);// number tmp = String(tmp); alert(typeof tmp);// string // string to number var tmp = "100"; alert(typeof tmp);// string tmp = Number(tmp); alert(type..
Variables concept typescript variables// There are 3 basic types in Typescript var isDone: boolean = false; var age: number = 42; var myName: string = "Anders"; // Not sure which the type of the variable is var notSure: any = true; notSure = 23; notSure = "maybe a string"; null vs undefined // prints null var emptyVariable = null; console.log(emptyVariable); // prints undefined var newVariable; console.log(newVar..
Intro to Typescript Javascript that scales classesmodulesinterfacesgenericsstatic typing(optional) Setting npm install -g typescripttsc -vtsc main.tsmain.ts 파일을 main.js로 변환 typescript test? 필요한 파일들을 만들고, web browser에서 직접 확인terminal / cmd에서 console 확인typescript/javascript playground에서 직접 확인(http://www.typescriptlang.org/play)web browser에서 console 확인