웹/JavaScript & JQuery
[JavaScript] function 객체의 메서드 call(), apply()
느링
2019. 2. 14. 12:13
메서드 활용
function thisIsFunction(x, y, z){
console.log(this, x, y, z);
}
1. call( )
thisIsFunction.call( document.body , 100 , 200 , 300);
첫번째 인자 -> this에 무엇으로 사용할 것인지
나머지 인자들 -> 각각의 값에 대입이 되는 것임
2. apply( )
thisIsFunction.apply( document.body , [100 , 200 , 300]);
//call과 유사함, 하지만 call과 차이점은 배열로 값을 전달함