Possible Duplicate:
What is the difference between call and apply?
What is the main difference between apply and call methods…
I go through the web but unable to find the best solution..
Please help me friends…
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Every function in JavaScript receives two objects in addition to the default parameters. These are
thisandarguments. The value ofthisis determined by it’s invocation pattern.applyorcallcan be used to invoke a function and provide it a defaultthisobject.This will be very useful in many situations. For example,
argumentsis an array-like object, but not really anArraywith all the useful Array methods. So, to apply an Array methodsliceonarguments, you can do this:Had
argumentsbeen an object ofArraytype, you could have usedcallis nothing but a modified version of apply. See elusive’s comment.Mr.Douglus Crockford gives a very good introduction to JavaScript functions in this video: Function the Ultimate.