11. ํ”„๋กœํ† ํƒ€์ž…

11-1. ํ”„๋กœํ† ํƒ€์ž… ์‚ฌ์šฉ ์‚ฌ๋ก€

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ ๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ๋Š” ํ”„๋กœํ† ํƒ€์ž… ์ƒ์†, ๊ฐ์ฒด ๋ฆฌํ„ฐ๋Ÿด ๋“ฑ์ด ์žˆ๋‹ค. ๋ชจ๋“  ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ํ•จ์ˆ˜๋Š” ํ”„๋กœํ† ํƒ€์ž…์„ ๊ฐ€์ง€๋ฉฐ, ๋นŒํŠธ์ธ ์˜ค๋ธŒ์ ํŠธ ๋˜ํ•œ ํ”„๋กœํ† ํƒ€์ž…์ด ์žˆ๋‹ค. ๋งŒ์•ฝ ํ”„๋กœํ† ํƒ€์ž…์ด ์—†์œผ๋ฉด ํ•จ์ˆ˜๋Š” ์ˆ˜๋ช…์ด ๋๋‚˜๋ฉฐ ํ•ด๋‹น ํ•จ์ˆ˜์˜ ์ธ์Šคํ„ด์Šค๊ฐ€ ๋ฉ”๋ชจ๋ฆฌ์—์„œ ํ•ด์ œ๋œ๋‹ค.
 
ํ”„๋กœํ† ํƒ€์ž…์„ ๊ฐ€์ง€๋Š” ๋นŒํŠธ์ธ ์˜ค๋ธŒ์ ํŠธ๋“ค
notion image
 

11-2. ํ”„๋กœํ† ํƒ€์ž…์˜ ์ •์˜

๋ชจ๋“  ๊ฐ์ฒด๋Š” ํ”„๋กœํ† ํƒ€์ž… ๊ฐ์ฒด๋ฅผ ๊ฐ€์ง€๋ฉฐ, ์ด ํ”„๋กœํ† ํƒ€์ž… ๊ฐ์ฒด๋Š” ํ•ด๋‹น ๊ฐ์ฒด์˜ ๊ธฐ๋Šฅ๊ณผ ์†์„ฑ์„ ์ •์˜ํ•œ๋‹ค. ๊ฐ์ฒด์˜ ์†์„ฑ๊ณผ ๋ฉ”์„œ๋“œ๋Š” ํ”„๋กœํ† ํƒ€์ž… ๊ฐ์ฒด์—์„œ ์ƒ์†๋œ๋‹ค. ์ด๋ ‡๊ฒŒ ์ƒ์† ๊ด€๊ณ„๋ฅผ ํ†ตํ•ด โ€˜๊ฐ์ฒดโ€™ ๊ฐ„์— ๊ณตํ†ต๋œ ๊ธฐ๋Šฅ์„ ์žฌ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

11-2-1. ์ƒ์„ฑ์ž ํ•จ์ˆ˜์™€ ํ”„๋กœํ† ํƒ€์ž…

์ƒ์„ฑ์ž ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค๋ฉด ์ž๋™์œผ๋กœ ํ”„๋กœํ† ํƒ€์ž…์ด ํฌํ•จ๋œ๋‹ค.
// ์ƒ์„ฑ์ž ํ•จ์ˆ˜ function Person(name) { this.name = name; } // ํ”„๋กœํ† ํƒ€์ž…์— ๋ฉ”์„œ๋“œ ์ถ”๊ฐ€ Person.prototype.greet = function() { console.log(`Hello, my name is ${this.name}`); }; // ๊ฐ์ฒด ์ƒ์„ฑ const person1 = new Person('Alice'); const person2 = new Person('Bob'); // ๋ฉ”์„œ๋“œ ํ˜ธ์ถœ person1.greet(); // ์ถœ๋ ฅ: Hello, my name is Alice person2.greet(); // ์ถœ๋ ฅ: Hello, my name is Bob
์œ„ ๋ฐฉ๋ฒ•์ฒ˜๋Ÿผ Person์„ ์ •์˜ํ•˜์—ฌ person1์™€ person2์˜ greet() ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค
 
 

11-2-2. ์ƒ์„ฑ์ž์™€ ํ”„๋กœํ† 

๋น„์Šทํ•œ ๊ฐ์ฒด๋“ค์€ ๋น„์Šทํ•œ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•˜๋ฏ€๋กœ, ๊ณตํ†ต๋œ ๊ธฐ๋Šฅ์„ ๊ณต์œ ํ•˜๋Š” ๊ฒƒ์ด ํšจ์œจ์ ์ด๋‹ค. ํ•˜์ง€๋งŒ ๋•Œ๋กœ๋Š” ๊ฐ์ฒด๋“ค์ด ๊ฐ์ž ๋…๋ฆฝ์ ์ธ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•ด์•ผ ํ•˜๋Š” ์ƒํ™ฉ๋„ ์žˆ๋‹ค.
function Taiyaki(){ this.filling = "ํŒฅ"; } const taiyaki1 = new Taiyaki(); const taiyaki2 = new Taiyaki(); //taiyaki1์˜ ํ”„๋กœํ† ์— ์‚ฐ์ž… taiyaki1.__proto__.setFilling = function(ReFilling){ this.filling = ReFilling return this.filling+"์œผ๋กœ ์ฑ„์šด๋‹ค" } //taiyaki1์˜ ํฌ๋กœํ† ํƒ€์ž…์— ์‚ฐ์ž… taiyaki1.eat = function(newFilling){ return this.filling + "์„ ๋จน๋‹ค" } console.log(taiyaki1.setFilling("ํฌ๋ฆผ")) // ํฌ๋ฆผ์œผ๋กœ ์ฑ„์šด๋‹ค console.log(taiyaki1.eat()) // ํฌ๋ฆผ ๋จน๋‹ค console.log(taiyaki2.setFilling("์น˜์ฆˆ")) // ์น˜์ฆˆ์œผ๋กœ ์ฑ„์šด๋‹ค console.log(taiyaki2.eat()) // ์—๋Ÿฌ
์œ„์˜ ๋กœ์ง์„ ๋ณด๋ฉด console.log(taiyaki2.eat()) ์—์„œ ์—๋Ÿฌ๊ฐ€ ๋– ์•ผ ํ•œ๋‹ค. ์•„์ง ํŒ”๋ฆฌ์ง€ ์•Š์€ taiyaki2 ๋Š” ์ž์‹ ์ด ์–ด๋– ํ•œ ๋ชฉ์ ์œผ๋กœ ๊ตฌ๋งคํ•˜์˜€๋Š”์ง€ ๋ชจ๋ฅด๊ธฐ ๋•Œ๋ฌธ์— ๋ฉ”์†Œ๋“œ๋ฅผ ์ถ”๊ฐ€ ํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์ด ์˜ฌ๋ฐ”๋ฅด๋‹ค. ๊ทธ๋ž˜์„œ eat()์ด๋ผ๋Š” ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๊ฒŒ ํ•ด์•ผ ํ•œ๋‹ค.
taiyaki1.__proto__.setFilling = function(ReFilling){ this.filling = ReFilling return this.filling+"์œผ๋กœ ์ฑ„์šด๋‹ค" }
๋ฐ˜๋ฉด setFilling ์ด๋ผ๋Š” ๋‚ด์šฉ์„ ๋ฐ”๊พธ๋Š” ์ƒํƒœ๋Š” ๋ชจ๋“  ๊ฐ์ฒด๊ฐ€ ์•Œ ์ˆ˜ ์žˆ์–ด์•ผ ํ•œ๋‹ค.
๊ทธ๋Ÿฌํ•˜๊ธฐ ์œ„ํ•ด proto ์— ํ•จ์ˆ˜๋ฅผ ๋„ฃ์—ˆ๋‹ค proto ์— ํ•จ์ˆ˜๋ฅผ ๋„ฃ์€ ์ž์›์€ ๊ฐ™์€ ์ƒ์„ฑ์ž๋ฅผ ์‚ฌ์šฉํ•œ ๊ฐ์ฒด์— ๊ณต์œ ํ•œ๋‹ค.
taiyaki1.eat = function(newFilling){ return this.filling + "์„ ๋จน๋‹ค" }
๋จน๋Š”๋‹ค๋Š” ํŒ๋‹จ์€ ํŒ”๋ฆฐ ๊ฐ์ฒด taiyaki1๋งŒ ์•Œ์•„์•ผ ํ•œ๋‹ค. ๋งŒ์ผ ๋จน์ง€ ์•Š๊ณ  ๋‹ค๋ฅธ ์‚ฌ๋žŒํ•œํ…Œ ์–‘๋„ํ•˜๊ฑฐ๋‚˜ ๋ณด๊ด€ํ•œ๋‹ค๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜๋„ ์žˆ๊ณ , ๊ฒฐ๊ตญ ๋งˆ์ง€๋ง‰์—” ๋จน์ง€๋„ ๋ชปํ•˜๊ณ  ๋ฒ„๋ฆด ์ˆ˜๋„ ์žˆ๋‹ค. ๊ทธ๋ž˜์„œ taiyaki1 ํ”„๋กœํ† ํƒ€์ž…์„ ๋„ฃ์–ด์„œ ํ•ด๋‹น ๊ฐ์ฒด๋งŒ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ํ•จ์ˆ˜๋ฅผ ๋„ฃ์–ด, ๋‹ค๋ฅธ ๊ฐ์ฒด์—์„œ ์˜ค๋ฅ˜๋ฅผ ์ผ์œผํ‚ฌ ๋งŒํ•œ ๋ฉ”์„œ๋“œ๋ฅผ ์ฃผ์ง€ ์•Š๋Š” ๊ฒƒ์ด ๋ฐ”๋žŒ์งํ•˜๋‹ค.
 

11-2-3. ๊ฐ™์€ ๊ฐ’์„ ๊ฐ€์ง„ ํ”„๋กœํ† 

๊ฐ์ฒด์—์„œ ํ”„๋กœํ† ํƒ€์ž… ๊ฐ์ฒด๋ฅผ ๊ฐ€๋ฆฌํ‚ค๋Š” ๋งํฌ๋ฅผ ๊ฐ€์ง€๋ฉฐ, ์ด ๋งํฌ๋ฅผ ๋”ฐ๋ผ ์ƒ์œ„ ํ”„๋กœํ† ํƒ€์ž… ๊ฐ์ฒด๋ฅผ ์ฐพ๋Š” ๊ณผ์ •์„ ํ”„๋กœํ† ํƒ€์ž… ์ฒด์ธ์ด๋ผ๊ณ  ํ•œ๋‹ค. ๋งŒ์•ฝ ๊ฐ์ฒด์—์„œ ์–ด๋–ค ์†์„ฑ์ด๋‚˜ ๋ฉ”์„œ๋“œ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์„ ๋•Œ๋Š” ์ด ์ฒด์ธ์„ ๋”ฐ๋ผ ์ƒ์œ„ ํ”„๋กœํ† ํƒ€์ž… ๊ฐ์ฒด์—์„œ ์ฐพ๋Š”๋‹ค.
์ƒ์„ฑ์ž ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๊ธฐ๋ณธ์ ์ธ ํ”„๋กœํ† ํƒ€์ž…์€ ๊ณต์œ ๋œ๋‹ค.
function Person(name) { this.name = name; } let person = new Person('John'); console.log(person.__proto__=== Person.prototype); // true
์œ„์ฒ˜๋Ÿผ ํ”„๋กœํ† ํƒ€์ž…์„ ๊ทธ๋Œ€๋กœ ๋“ค๊ณ  ์™€์„œ ๋ถ€๋ชจ์— ์žˆ๋Š” prototype๊ณผ __proto__๋Š” ์™„์ „ํžˆ ๊ฐ™๋‹ค.
์ด๋ ‡๊ฒŒ ์™„์ „ํžˆ ๊ฐ™์œผ๋ฉด ๋‘ ๊ฐœ์˜ ํด๋ž˜์Šค๋ฅผ ํ•ฉ์น˜๋Š” ๊ฒƒ ๋˜ํ•œ ๊ฐ€๋Šฅํ•˜๋‹ค.
// ๋ถ€๋ชจ ์ƒ์„ฑ์ž ํ•จ์ˆ˜ function Animal(name) { this.name = name; } // ๋ถ€๋ชจ ์ƒ์„ฑ์ž ํ•จ์ˆ˜์˜ ํ”„๋กœํ† ํƒ€์ž…์— ๋ฉ”์„œ๋“œ ์ถ”๊ฐ€ Animal.prototype.sayName = function() { console.log(`I am ${this.name}`); }; // ์ž์‹ ์ƒ์„ฑ์ž ํ•จ์ˆ˜ function Dog(name, breed) { Animal.call(this, name); // ๋ถ€๋ชจ ์ƒ์„ฑ์ž ํ˜ธ์ถœ this.breed = breed; } // ์ž์‹ ์ƒ์„ฑ์ž ํ•จ์ˆ˜๊ฐ€ ๋ถ€๋ชจ ์ƒ์„ฑ์ž ํ•จ์ˆ˜์˜ ํ”„๋กœํ† ํƒ€์ž…์ฒด์ธ์„ ์ƒ์† Dog.prototype = Object.create(Animal.prototype); // ์ž์‹ ์ƒ์„ฑ์ž ํ•จ์ˆ˜์— ์ถ”๊ฐ€๋œ ๋ฉ”์„œ๋“œ Dog.prototype.bark = function() { console.log('Woof!'); }; // ๊ฐ์ฒด ์ƒ์„ฑ const dog = new Dog('Buddy', 'Golden Retriever'); // ๋ฉ”์„œ๋“œ ํ˜ธ์ถœ dog.sayName(); // ์ถœ๋ ฅ: I am Buddy dog.bark(); // ์ถœ๋ ฅ: Woof!
์œ„์ฒ˜๋Ÿผ ๋‘ ๊ฐ€์ง€ ํ”„๋กœํ† ํƒ€์ž…์„ ํ•ฉ์ณ์„œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ ๋˜ํ•œ ๊ฐ€๋Šฅํ•˜๋‹ค.

11-2-4. ํ”„๋กœํ† ํƒ€์ž… ๊ฐ„์˜ ์†Œํ†ต ๊ณต์œ  ๋ฒ”์œ„

function Animal(name) { console.log(this.name + 'ํ•จ์ˆ˜ ์•ˆ'); } // ๋ถ€๋ชจ ์ƒ์„ฑ์ž ํ•จ์ˆ˜์˜ ํ”„๋กœํ† ํƒ€์ž…์— ๋ฉ”์„œ๋“œ ์ถ”๊ฐ€ Animal.prototype.getName = function () { this.setName(); console.log(this.name + 'ํ”„๋กœํ† ํƒ€์ž… ์•ˆ'); }; Animal.prototype.setName = function () { this.name = 100; }; const myAnimal = new Animal('Fido'); myAnimal.getName(); // undefined ํ•จ์ˆ˜ ์•ˆ, Fido๋Š” function Animal ์•ˆ์œผ๋กœ ๋“ค์–ด๊ฐ€์ง€ ์•Š๋Š”๋‹ค. // 100 ํ”„๋กœํ† ํƒ€์ž… ์•ˆ, getName์„ ํ˜ธ์ถœ ์‹œ Fido๊ฐ€ ๋ฌด์‹œ๋˜๊ณ  100์ด ๋“ค์–ด๊ฐ„๋‹ค.
Animal์€ โ€˜์ƒ์„ฑ์ž ํ•จ์ˆ˜โ€™์ด๊ณ  getName์€ โ€˜ํ”„๋กœํ† ํƒ€์ž…โ€™์— ์žˆ๋‹ค. ๋”ฐ๋ผ์„œ, this๋Š” ๊ฐ๊ฐ ๋‹ค๋ฅธ ๊ฐ์ฒด๋ฅผ ๊ฐ€๋ฆฌํ‚จ๋‹ค. Animal ํ•จ์ˆ˜ ๋‚ด์—์„œ์˜ this๋Š” ์ƒˆ๋กœ ์ƒ์„ฑ๋œ Animal ๊ฐ์ฒด๋ฅผ ๊ฐ€๋ฆฌํ‚ค๊ณ , setName ํ•จ์ˆ˜ ๋‚ด์—์„œ์˜ this๋Š” ๋™์ผํ•œ Animal ๊ฐ์ฒด๋ฅผ ๊ฐ€๋ฆฌํ‚จ๋‹ค. getName ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ, setName ํ•จ์ˆ˜์—์„œ ์„ค์ •๋œ this.name ๊ฐ’์ธ 100์ด ์ถœ๋ ฅ๋œ๋‹ค.
 

11-3. ํ˜„์—…์—์„œ ํ”„๋กœํ† ํƒ€์ž…๊ณผ ์ƒ์„ฑ์ž๋ฅผ ์‚ฌ์šฉ ๋ฐฉ๋ฒ•

๋‹ค์Œ์€ ๋ฉ”์„œ๋“œ ์ฒด์ด๋‹๊ณผ ํ”„๋กœํ† ํƒ€์ž…, ์•„๊ทœ๋จผํŠธ์˜ ๊ฐ’์„ ํ™œ์šฉํ•œ ์˜ˆ์ œ์ฝ”๋“œ์ด๋‹ค.
function Vector(x, y) { this.x = x || 0; this.y = y || 0; } Vector.prototype = { // ์ž…๋ ฅ๊ฐ’์ด ํ•˜๋‚˜์ด๋ฉด {x.x x.y} ๋‘ ๊ฐœ์ด๋ฉด {x, y} add: function (x, y) { if (arguments.length === 1) { // ๊ฐ’์ด ํ•˜๋‚˜์ด๋ฉด ์•„๋ž˜ ๋กœ์ง ์‹คํ–‰ this.x += x.x; this.y += x.y; } else if (arguments.length === 2) { // ๊ฐ’์ด ๋‘ ๊ฐœ์ด๋ฉด ์•„๋ž˜ ๋กœ์ง ์‹คํ–‰ this.x += x; this.y += y; } // ๋ฉ”์„œ๋“œ ์ฒด์ด๋‹์„ ์œ„ํ•œ ๋ฐ˜ํ™˜๊ฐ’ this return this; }, sub: function (x, y) { if (arguments.length === 1) { this.x -= x.x; this.y -= x.y; } else if (arguments.length === 2) { this.x -= x; this.y -= y; } return this; }} Vector.sub = function (v1, v2) { // ์•„๊ทœ๋จผํŠธ๋ฅผ ๋ฐ›๊ณ  v1์—์„œ v2๋ฅผ ๋นผ ๋‹ค์‹œ ๋ฒกํ„ฐ๋ฅผ ๋งŒ๋“ ๋‹ค. // ํ•˜์ง€๋งŒ ์œ„์— ํ”„๋กœํ† ํƒ€์ž…์— sub๋ฅผ ์ •์˜ํ•ด์„œ ์•„๊ทœ๋จผํŠธ ๊ฐœ์ˆ˜๊ฐ€ ํ•œ ๊ฐœ์ธ์ง€ ๋‘ ๊ฐœ์ธ์ง€ ํ™•์ธํ•˜๊ณ  ์ ์šฉํ•œ๋‹ค. return new Vector(v1.x - v2.x, v1.y - v2.y); }; Vector.add = function (v1, v2) { // ์œ„์— ํ”„๋กœํ† ํƒ€์ž…์— add๋ฅผ ์ •์˜ํ•ด์„œ ์•„๊ทœ๋จผํŠธ ๊ฐœ์ˆ˜๊ฐ€ ํ•œ ๊ฐœ์ธ์ง€ ๋‘ ๊ฐœ์ธ์ง€ ํ™•์ธํ•˜๊ณ  ์ ์šฉํ•œ๋‹ค. return new Vector(v1.x + v2.x, v1.y + v2.y); }; const v1 = new Vector(3, 4); const v2 = new Vector(2, 3); const resultAdd = Vector.add(v1, v2); const resultSub = Vector.sub(v1, v2); console.log('๋ง์…ˆ ๊ฒฐ๊ณผ: (' + resultAdd.x + ', ' + resultAdd.y + ')');// ๋ง์…ˆ ๊ฒฐ๊ณผ: (5, 7) console.log('๋บ„์…ˆ ๊ฒฐ๊ณผ: (' + resultSub.x + ', ' + resultSub.y + ')');// ๋บ„์…ˆ ๊ฒฐ๊ณผ: (1, 1) const v3 = {x:2,y:2}; const resultOneArgAdd =v1.add(v3); console.log('์Šค์นผ๋ผ ๋ง์…ˆ ๊ฒฐ๊ณผ: (' + resultOneArgAdd.x + ', ' + resultOneArgAdd.y + ')');// ์Šค์นผ๋ผ ๋ง์…ˆ ๊ฒฐ๊ณผ: (5, 6) const resultOneArgSub = v1.sub(v3); console.log('์Šค์นผ๋ผ ๋บ„์…ˆ ๊ฒฐ๊ณผ: (' + resultOneArgSub.x + ', ' + resultOneArgSub.y + ')');// ์Šค์นผ๋ผ ๋บ„์…ˆ ๊ฒฐ๊ณผ: (3, 4) const v4 = new Vector(2, 3); // ๋ฉ”์„œ๋“œ ์ฒด์ด๋‹ v4.add(1, 2).sub(2, 1); console.log(v4)// { x: 1, y: 4 }
๋ฐฑ์—”๋“œ ๊ธฐ์ค€์—์„œ๋Š” ๋‹ค์–‘ํ•œ ๋””์ž์ธ ํŒจํ„ด๊ณผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜์ง€๋งŒ ์œ„ ํ”„๋กœ๊ทธ๋žจ์€ ํ”„๋ก ํŠธ์—”๋“œ์—์„œ๋„ ์บ”๋ฒ„์Šค ๋“ฑ์— ์‚ฌ์šฉํ•˜๋Š” ๋กœ์ง์ด๋‹ค.
this.x += x; this.y += y;
์œ„ ๋กœ์ง์œผ๋กœ ๊ฐ๊ฐ์˜ this์— ์žˆ๋Š” x์™€ y๋ฅผ ์ฆ๊ฐ€์‹œํ‚จ๋‹ค.
Vector.prototype = { add: function (x, y) { if (arguments.length === 1) { this.x += x.x; this.y += x.y; } else if (arguments.length === 2) { this.x += x; this.y += y; } return this; },
๋งˆ์ง€๋ง‰์œผ๋กœ ๋ฉ”์„œ๋“œ ์ฒด์ด๋‹์€ ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•œ ํ›„์—๋„ ๋ฉ”์„œ๋“œ๋ฅผ ๋ฐ˜ํ™˜ํ•˜์—ฌ ์—ฐ์†์ ์œผ๋กœ ํ˜ธ์ถœ์„ ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•˜๋Š” ํŒจํ„ด์ด๋‹ค. ์ด ํŒจํ„ด์€ ๋ณดํ†ต ๋ฉ”์„œ๋“œ๊ฐ€ ์ž๊ธฐ ์ž์‹ ์„ ๋ฐ˜ํ™˜ํ•จ์œผ๋กœ์จ ์ฒด์ด๋‹์„ ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•˜๋‹ค.
v4.add(1, 2).sub(2, 1);