1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| function Person(name, nickname) { this.name = name; this.nickname = nickname;
this.sayHi = function () { console.log(this.name, this.nickname, 'hello', this); }; }
const sung = new Person('sung', 'superpower'); const sung2 = new Person('sung', 'superpower');
console.log(sung.sayHi === sung2.sayHi);
Person.prototype.sayHello = function () { console.log('sayHello prototype'); console.log(this.name, this.nickname, 'hello', this); };
console.log(sung.sayHello === sung2.sayHello);
|