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' 객체와 체인 관계를 알 수 있다.
또한 아래와 같이 객체 리터럴 형식으로도 똑같이 나타낼 수 있다.
const b = ['red', 'blue', 'green'];
console.log(b, typeof b);
console.log(b instanceof Array);
console.log(b instanceof Object);
[Running]
[ 'red', 'blue', 'green' ] object
true
true
Array 객체 속에 내장되어 있는 'slice' 함수를 써보자.
console.log(b.slice(0,1));
console.log(Array.prototype.slice, Object.prototype.slice);
[Running]
[ 'red' ]
[Function: slice] undefined
'slice(0,1)'의 의미는 0번째부터 1개 값만 잘라서 가져오겠다는 의미이다.
그래서 아래에 'red'만 출력되었다.
또한 두번째 코드를 보면 Array 객체의 프로토타입에는 slice가 내장되어 있지만, Object에는 내장되어 있지 않음을 알 수 있다.
'JavaScript' 카테고리의 다른 글
JavaScript 기초(27)_클래스(2) property (0) | 2021.10.24 |
---|---|
JavaScript 기초(26)_클래스(1) constructor (0) | 2021.10.23 |
JavaScript 기초(24)_객체(4) (0) | 2021.10.21 |
JavaScript 기초(23)_객체(3) (0) | 2021.10.20 |
JavaScript기초(22)_객체(2) (0) | 2021.10.16 |
댓글