function Person(){ this.name = 'park'; this.first = 50; this.second = 30; this.third = 20; this.sum = function(){ return this.first + this.second + this.third; } } console.log(Person()); console.log(new Person());
- 단지 함수일 뿐 - undefined
- Person이라는 함수 객체가 생성
Person {
name: 'park',
first: 50,
second: 30,
third: 20,
sum: [Function (anonymous)]
}
function Person(){ this.name = 'park'; this.first = 50; this.second = 30; this.third = 20; this.sum = function(){ return this.first + this.second + this.third; } } var student1 = new Person(); var student2 = new Person();
function Person(name, first, second, third){ this.name = name; this.first = first; this.second = second; this.third = third; this.sum = function(){ return this.first + this.second + this.third; } } var student1 = new Person('park', 20, 30, 40); var student2 = new Person('lee', 30, 40, 10); console.log(student1.sum()); console.log(student2.sum());
- 값은 90, 80이 나온다