클래스 컴포넌트import React from 'react'// props 타입 선언interface Props { required?: boolean text: string}// state 타입 선언interface State { count: number isLimited?: boolean}class Component extends React.Component { private constructor(props : Props) { super(props) this.state = { count: 0, isLimited: false, } } render() { const { props: {required, t..
클래스란자바스크립트의 클래스란 특정한 객체를 만들기 위한 일종의 템플릿클래스를 활용하면 객체를 만드는 데 필요한 데이터나 이를 조작하는 코드를 추상화해 객체 생성을 더욱 편리하게 할 수 있음class Car { // 생성자 constructor(name) { this.name = name; } // 메서드 hook() { console.log('경적을 울립니다'); } // 정적 메서드 static hello() { console.log('안녕, 자동차야!'); } // setter set age(value) { this.carAge = value } //getter get age()..
객체지향 프로그래밍 언어인 자바스크립트자바스크립트는 프로토타입 기반 객체지향 언어. 따라서 클래스가 필요 없음클래스 없이도 생성자 함수와 프로토타입을 통해 객체지향 언어의 상속 구현 가능함ES6에서 도입된 클래스는 기존 프로토타입 기반 객체지향 프로그래밍보다 자바나 C#에 익숙한 프로그래머가 빠르게 학습할 수 있는 객체 생성 매커니즘 제시var Person = (function () { //생성자 함수 function Person(name) { this.name = name; } //프로토타입 메서드 Person.prototype.sayHi = fuction () { console.log('Hi, My name is '+this.name); }; ..
Prototype 생성자를 통해서 반환된 인스턴스에서 쓸 수 있는 별도의 속성이나 메소드를 등록하는 객체 클래스 ES6 Class class User { constructer (first, last) { this.firstName = first; this.lastName = last; } getFullName() { return `${firstName} ${lastName}` } } const person = new User('Potter','Harry') person.getFullName() Getter 값을 얻어내는 용도의 메소드 Get 키워드를 사용하여 함수를 작성하면 하나의 속성처럼 사용 가능함 class User { constructer (first, last) { this.firstName =..