Function. prototype. call. apply combined with usage analysis example _ javascript skills
Source: Internet
Author: User
Yesterday I saw an interesting js interview question: varaFunction. prototype. call. apply (function (a) {returna;}, [, 3]); alert (a); the analysis steps are as follows, if you are interested, you can refer to the following: I saw an interesting js interview question on the internet yesterday. I discussed it with my colleagues and found that at the beginning, I was very confused, after understanding this, I found it quite simple to share with you!
The question is as follows: var a = Function. prototype. call. apply (function (a) {return a ;}, [, 3]); alert ();
The analysis procedure is as follows: 1. Use Function. prototype. call as a whole. The call method is a local method implemented by the browser and an internal method of the Function type.
Var a = (Function. prototype. call). apply (function (a) {return a ;}, [0, 4, 3]);
2. fun. apply (obj, args) is equivalent to obj. fun (args). This step is important and must be understood!
(Function (a) {return a;}). apply (0, [4, 3])
(Function (a) {return a;}). call (0, 4, 3)
3. The result in this step is obvious. a is 4, and alert is 4.
The confusion of this question lies in Function. prototype. call. After understanding it, it is clear!
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service