Function. Prototype. Call. Apply combined with usage analysis example

Source: Internet
Author: User

I saw a very interesting JS interview question on the internet yesterday and discussed it with my colleagues. I found it quite simple at the beginning, and I will share it 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!

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.