본문 바로가기

Language/JavaScript

(3)
Class JavaScript는 프로토타입을 사용한 상속을 사용한다. // 기본적인 예제 function Vacation(destination, length) { this.destination = destination; this.length = length; } Vacation.prototype.print = function() { console.log(this.destination + "은(는)" + this.length + "일 걸립니다.") }; const maui = new Vacation("마우이", 7); maui.print(); class Vacation { constructor(destination, length) { this.destination = destination; this.length = ..
JavaScript for React 2 - 객체(Object)와 배열(Array) const sandwich = { bread: "더치 크런치", meat: "참치", cheese: "스위스", toppings: ["상추","토마토","머스타드"] }; const {bread, meat} = sandwich; console.log(bread, meat); // 더치 크런치 참치 위의 코드는 bread와 meat에 sandwich에 있는 같은 이름의 필드 값으로 초기화 된다. const lordify = reqularPerson => { console.log(`캔터베리의 ${reqularPerson.firstname}`); }; var reqularPerson = { firstname: "현석", lastname: "오" }; lordify(r..
JavaScript for React 1 - 변수 선언하기 - const var pizza = true; pizza = false; console.log(pizza); // false 위의 코드는 선언된 변수 pizza가 재선언이 되는 경우다. 변경되지 않는 변수는 const로 선언하면 변경되지 않는다. const pizza = true; - let var topic = "자바스크립트"; if (topic) { var topic = "리액트"; console.log('블록', topic) // 블록 리액트 } console.log('글로브', topic); // 글로벌 리액트 topic의 재선언을 했을 때, if 블록 밖에서도 변경됨. var topic = "자바스크립트"; if (topic) { let topic = "리액트"; console..