본문 바로가기

객체5

JavaScript 기초(25)_객체(5) 1. 표준 내장 객체 : 자바스크립트 자체에 내장되어있는 객체이다. MDN 검색하여 참고하면서 사용하시면 된다. 아래는 대표적인 몇 가지 표준 내장 객체를 소개하고자 한다. Array 객체 const a = new Array('red', 'blue', 'green'); console.log(a, typeof a); console.log(a instanceof Array); console.log(a instanceof Object); [Running] [ 'red', 'blue', 'green' ] object true true 'instanceof'를 통해 'Array' 객체뿐만이 아닌 'Object' 객체와 체인 관계를 알 수 있다. 또한 아래와 같이 객체 리터럴 형식으로도 똑같이 나타낼 수 있다. c.. 2021. 10. 22.
JavaScript 기초(24)_객체(4) 1. 객체 리터럴 (Object Literal) : '객체를 직접 써서 만든다'는 의미이다. 아래의 예시 코드들을 통해 알아보자. const a = {}; console.log(a, typeof a); const b = { name : 'Kim' }; console.log(b, typeof b); [Running] {} object { name: 'Kim' } object 변수 a는 빈 객체이다. 변수 b는 name이 'Kim'인 객체이다. 두 객체 모두 중괄호로 직접 써서 객체를 만들었다. 위처럼 단순한 형태의 객체 말고 함수가 포함된 객체도 '직접 써서'(객체 리터럴 형태로) 아래와 같이 나타낼 수 있다. const c = { name : 'Kim', hello1(){ console.log('hell.. 2021. 10. 21.
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기초(21)_객체(1) 함수, 클래스 (틀) => 객체, 개체, object : 함수, 클래스 등의 틀을 이용해서 여러 객체(object)를 찍어내는 개념이다. 1. function 틀() {} => new 틀 () 비어있는 생성자 함수를 만들어보자. function A(){} // 텅빈 함수 A 생성함. const a = new A(); // 변수 a에 생성자함수 A를 선언함. = 객체 생성 console.log(a, typeof a); // 생성된 객체 a 와 a의 타입을 출력함. console.log(A()); // 함수 A() 자체를 출력함. [Running] A {} object undefined 객체 a를 출력하니 텅 빈 함수 'A {}'가 출력되었고, 'new A()'(생성자 함수)로 선언한 a의 타입은 'obje.. 2021. 10. 15.