new
연산자와 함께 Object 생성자 함수를 호출하면 빈 객체를 생성하여 반환한다// 빈 객체의 생성 const person = new Object(); // 프로퍼티 추가 person.name = 'Lee'; person.sayHello = function () { console.log('Hi! My name is ' + this.name); }; console.log(person); // {name: "Lee", sayHello: f} person.sayHello(); // Hi! My name is Lee
function Circle(radius) { // 1. 암묵적으로 인스턴스가 생성되고 this에 바인딩된다 // 2. this에 바인딩되어 있는 인스턴스를 초기화한다 this.radius = radius; this.getDiameter = function () { return 2 + this.radius; }; }