function
์ ์ฌ์ง์ function
function์ method๊ฐ ์๋!
method
์ ์ฌ์ง์ method
method ๋ ํด๋์ค ์์ ์๋ function ์ด๋ค. (ํด๋์ค๋ง ์๋ค๋ฉด ์๋ฌด ๋ณผํ ์๋ค. ํด๋์ค๋ method ๊ฐ ํ์ํจ)
๋ชจ๋ method ์ ์ฒซ๋ฒ์งธ argument (์ธ์) ๋
=> method๋ฅผ ํธ์ถํ๋ instance ์์ ์ด๋ค.
method ๋ฅผ ํธ์ถํ ๋ ๊ทธ method ์ instance ๋ฅผ ์ฒซ๋ฒ์งธ argument ๋ก ์ฌ์ฉํจ.
๋ฐ๋ณต ํ์ต
method๋ class ์์ ์๋ function
method() ์์ ์๋ฌด๊ฒ๋ ์ ๋ฃ๊ณ ์คํํ๊ณ ์ถ์ผ๋ฉด (self)๋ฅผ ๋ฃ์ด์ค๋ผ. ๊ทธ๋ ์ง ์์ผ๋ฉด method๋ฅผ ์ด์ฉํ ๋ ๋ง๋ค instance ๋ช ์ ()์์ ๋ฃ์ด์ค์ผ ํ ๊ฒ์ด๋ค.
๋ค์ํ๋ฒ๋~~~~~
method๋ class ์์ function ์ด๊ณ , ๊ทธ๋ฅ ํ๋์ function์ method๊ฐ ์๋๋ค
method๋ class๋ฅผ ์ฌ์ฉํ๊ณ ์ถ์๋, ()์ ์๋ฌด๊ฒ๋ ์๋ค๋ฉด ์ค์ค๋ก๋ฅผ ํธ์ถํด์ ์ฌ์ฉํ๋ค
ex) car.start() = car.start(car)
๊ทธ๋์ ๋ณดํต์ self๋ฅผ ๋ฃ์ด์ฃผ๊ณ , ๊ทธ๋ ๊ฒ ํ๋ ๊ฒ์ด ๋ณดํธ์ ์ด๋ค.
ex) car.start(self)