목록FrontEnd (27)
동그란 도그린
📍 일급 객체 무명의 리터럴로 생성 가능(런타임에 생성 가능) 변수나 자료구조에 저장 가능 함수의 매개변수에 전달 가능 함수 반환 값으로 사용 가능 함수가 일급 객체라는 것은 함수를 객체와 동일하게 사용 가능하다는 의미 📍 함수 객체의 프로퍼티 Object. prototype 객체의 프로퍼티는 모든 객체가 상속받아 사용 가능 arguments 프로퍼티 arguments 객체는 함수 호출 시 전달된 인수들의 정보를 담고 있는 순회 가능한 유사 배열 객체 함수 내부에서 지역 변수처럼 사용 함수 외부에서 참조 불가 매개변수의 개수를 확정할 수 없는 가변 인자 함수를 구현할 때 유용 배열 형태이지만, 실제로 배열이 아닌 유사 배열 객체 🔅 유사 배열 객체 : length 프로퍼티를 가진 객체로, for문으로 순..
📍 Object 생성자 함수 new 연산자와 함께 Object 생성자 함수를 호출하면 빈 객체를 생성하여 반환 🔅 생성자 함수 : new 연산자와 함께 호출, 객체(인스턴스)를 생성하는 함수 📍 생성자 함수 객체 리터럴에 의한 객체 생성 방식은 단 하나의 객체만 생성 ⇒ 동일한 프로퍼티를 갖는 객체를 여러개 생성해야 하는 경우에는 매번 같은 프로퍼티를 기술해야 함 ⇒ 비효율적 생성자 함수에 의한 객체 생성 방식은 객체 생성 템플릿(클래스)처럼 생성자 함수를 사용하여 프로퍼티 구조가 동일한 객체 여러 개를 간편하게 생성 가능 🔅 this : 객체 자신의 프로퍼티나 메서드를 참조하기 위한 자기 참조 변수 new 연산자와 함께 생성자 함수를 호출하지 않으면 생성자 함수가 아니라 일반 함수로 동작 생성자 함수가..
15-1장. var 키워드로 선언한 변수의 문제점var 키워드로 선언한 변수는 중복 선언 가능함var x = 1;var y = 1;// 초기화문이 있는 변수 선언문은 자바스크립트 엔진에 의해 var 키워드가 없는 것처럼 동작var x = 100;// 초기화문이 없는 변수 선언문은 무시됨var y;console.log(x); // 100console.log(y); // 1 var 키워드의 스코프var 키워드로 선언한 변수는 함수의 코드 블록만을 지역 스코프(변수가 유효한 범위)로 인정⇒ 함수 외부에서 var 키워드로 선언한 변수는 코드 블록 내에서 선언해도 모두 전역 변수가 됨⇒ 전역 변수를 남발할 가능성을 높인다var i = 1;// i는 전역 변수, 이미 선언된 i가 있으므로 중복 선언됨for(va..
14-1장. 변수의 생명 주기전역 변수의 무분별한 사용은 위험함 ⇒ 전역 변수를 반드시 사용해야 할 이유가 있는 게 아니라면 지역 변수를 사용해야 함 지역 변수의 생명 주기변수는 생성되고 소멸되는 생성 주기가 있음전역 변수의 생명 주기 : 어플리케이션의 생명 주기와 같음함수 내부에서 선언된 지역 변수의 생명 주기 : 함수가 호출되면 생성되고 함수가 종료하면 소멸됨 변수의 선언은 코드가 한 줄씩 순차적으로 실행되는 시점인 런타임에 실행되는 것 X, 런타임 이전 단계에서 자바스크립트 엔진에 의해 먼저 실행 O함수 내부에서 선언한 변수 ⇒ 함수가 호출된 직후에 함수 몸체의 코드가 한 줄씩 순차적으로 실행되기 이전에 자바스크립트 엔진에 의해 먼저 실행됨함수 내부에서 선언된 지역 변수⇒ 함수가 호출되어 실행되는 ..
13-1장. 스코프란?스코프란?모든 식별자(변수 이름, 함수 이름, 클래스 이름 등)는 자신이 선언된 위치에 의해 다른 코드가 식별자 자신을 참조할 수 있는 유효 범위가 결정됨⇒ 이를 ‘스코프’라고 함‘스코프’는 식별자가 유효한 범위를 말함프로그래밍 언어에서는 스코프(유효 범위)를 통해 식별자인 변수 이름의 충돌을 방지하여 같은 이름의 변수를 사용할 수 있게 함 ⇒ ‘스코프’는 네임스페이스임var 키워드로 선언한 변수는 같은 스코프 내에서 중복 선언이 허용됨 ⇒ 의도치 않게 변수 값이 재할당되어 변경되는 부작용을 발생시킴let이나 const 키워드로 선언된 변수는 같은 스코프 내에서 중복 선언을 허용하지 않음function foo() { var x = 1; var x = 2; // 변수값이 2..
📍 함수 자바스크립트의 함수는 객체 타입의 값 자바스크립트는 함수를 호출하기 위해 함수 이름과 동일한 이름의 식별자를 암묵적으로 생성 후 그 식별자에 객체를 할당 ⇒ 함수는 함수 이름이 아닌 함수 객체를 가리키는 식별자로 호출 함수 정의 방식 함수 선언문 function add (x,y) { return x+y; } 함수 표현식 var add = function (x,y) { return x+y; }; Function 생성자 함수 var add = new Function (’x’, ‘y’ ‘return x+y’); 화살표 함수 (ES6) var add = (x, y) ⇒ x+y; 함수 리터럴 function 키워드, 함수 이름, 매개변수 목록, 함수 몸체로 구성 함수 이름 생략 가능 (익명 함수) // ..
📍 원시 타입 변경 불가능한 값 (읽기 전용 값) 원시 값을 변수에 할당하면 변수에는 실제 값이 저장됨 원시 값을 갖는 변수를 다른 변수에 할당하면 원본의 원시 값이 복사되어 전달됨 (값에 의한 전달) 원시 값을 할당한 변수에 새로운 원시 값을 재할당하면, 새로운 메모리 공간을 확보하고 재할당한 원시 값을 저장한 후, 변수는 새롭게 재할당한 원시 값을 가리킴 원시 값을 할당한 변수는 재할당 이외에 변수 값을 변경할 수 있는 방법이 없음 문자열 문자열은 0개 이상의 문자로 이루어진 집합 1개의 문자는 2바이트의 메모리 공간에 저장됨 문자열은 유사 배열 객체이자 이터러블이므로 배열과 유사하게 각 문자에 접근 가능 🔅 유사 배열 객체 : 배열처럼 인덱스로 프로퍼티 값에 접근할 수 있고, length 프로퍼티를..
📍 객체 자바스크립트는 객체 기반의 프로그래밍 언어 객체는 원시 값을 제외한 나머지 값(함수, 배열, 정규 표현식 등) 원시 값은 변경 불가능한 값, 객체 값은 변경 가능한 값 객체는 0개 이상의 프로퍼티로 구성된 집합 프로퍼티 프로퍼티는 키와 값으로 구성 모든 값은 프로퍼티가 될 수 있음 프로퍼티 값이 함수이면, 이를 메서드라고 부름 객체는 프로퍼티와 메서드로 구성된 집합체 프로퍼티 : 객체의 상태 메서드 : 프로퍼티를 참조하고 조작할 수 있는 동작 📍 객체 리터럴에 의한 객체 생성 자바스크립트는 프로토타입 기반 객체지향 언어로, 다양한 객체 생성 방법 지원 객체 리터럴 Object 생성자 함수 생성자 함수 Object.create 메서드 클래스(ES6) 객체 리터럴 중괄호 내에 0개 이상의 프로퍼티 ..