생성자 함수2 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. JavaScript기초(18)_함수(4) 1. const hello = new Function(); Function 안에는 각 인자들과 함수의 바디를 아래와 같이 넣을 수 있다. // new Function( /* 인자1, 인자2, ... , 함수의 바디 */); const sum = new Function('a', 'b', 'c', 'return a + b + c'); console.log(sum(1,2,3)); [Running] 6 인자의 인식 범위에 대하여 다음과 같은 코드들을 통해 알 수 있다. { const a = 1; const test = new Function('return a'); console.log(test()); } [Running] return a ^ ReferenceError: a is not defined 변수 a가 .. 2021. 10. 12. 이전 1 다음