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!