๐Ÿšฉcall( )์€ ์ด๋ฏธ ํ• ๋‹น๋˜์–ด์žˆ๋Š” ๋‹ค๋ฅธ ๊ฐ์ฒด์˜ ํ•จ์ˆ˜ ๋˜๋Š” ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ํ•ด๋‹น ๊ฐ์ฒด์— ์žฌํ• ๋‹นํ•  ๋•Œ ์‚ฌ์šฉ๋œ๋‹ค.

โ€œthisโ€๋Š” ํ˜ธ์ถœํ•˜๊ณ  ์žˆ๋Š” ๊ฐ์ฒด ๋ฅผ ์ฐธ์กฐํ•œ๋‹ค.

๋ฉ”์†Œ๋“œ๋ฅผ ํ•œ๋ฒˆ ์ž‘์„ฑํ•˜๋ฉด, ์ƒˆ ๊ฐ์ฒด๋ฅผ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ๋ฅผ ์žฌ์ž‘์„ฑํ•  ํ•„์š” ์—†์ด call์„ ์ด์šฉํ•ด ๋‹ค๋ฅธ ๊ฐ์ฒด์— ์ƒ์†ํ•  ์ˆ˜ ์žˆ๋‹ค.

โœ

const kim = {
	name: 'kim',
	first: 10,
	second: 20,
}
const lee = {
	name: 'lee',
	first: 10,
	second: 10,
}
function sum(){
	return this.first + this.second;
}

console.log(sum.call(kim)); //30
console.log(sum.call(lee)); //20

โœ

function add(pre){
	return pre + (this.first + this.second);
}

console.log(sum.call(kim, '=> ')); //=> 30
console.log(sum.call(lee, ': ')); //: 20