프로토타입2 JavaScript 기초(23)_객체(3) 1. 프로토타입의 상속 프로토타입의 상속에 대한 기초적인 예제를 아래와 같이 작성해보았다. // prototype 상속 function Person(){ } Person.prototype.hello = function(){ console.log('hello'); } function Korean(region){ this.region = region; this.where = function(){ console.log('where', this.region); }; } Korean.prototype = Person.prototype; const k = new Korean('seoul'); k.hello(); k.where(); [Running] n hello where seoul 비어있는 함수 Person의 프.. 2021. 10. 20. JavaScript기초(22)_객체(2) 1. new Object() 우선 빈 객체를 만들어 그 결과 값과 타입을 출력하면 아래와 같이 나온다. const a = new Object(); console.log(a, typeof a); [Running] {} object Object에 true를 넣고 똑같이 출력해보자. const a = new Object(true); console.log(a, typeof a); [Running] [Boolean: true] object a는 불리언 true라는 결과 값과 타입은 객체라고 나온다. Object에 직접 리터럴 형태의 객체 값을 아래와 같이 넣으면 어떻게 될까? const a = new Object({name : 'Kim'}); console.log(a, typeof a); [Running] { n.. 2021. 10. 16. 이전 1 다음