Then the previous article, on the basis of the above to do a deformation.
Deformation one
Let's take a look at the demo below
<span style= "FONT-FAMILY:SIMSUN;FONT-SIZE:18PX;" ><script> var a = 1; function fn1 () { alert (a); A = 2; } function Fn1 (a) { alert (a); A = 2; } FN1 (); alert (a); var a = 1; function Fn1 (a) { alert (a); A = 2; } FN1 (); alert (a); </script></span>
Code Analysis
Look at the above code, there is another kind of wood dizzy feeling, this is where the sacred, can not understand ha! It's okay, let's analyze it slowly.
or according to the analysis I mentioned in the previous blog several steps, to analyze.
1. Get some stuff.
In the browser to resolve the pre-parsing, is to find some Var, function of things, and then after the PK placed into a warehouse inside. And the PK level is var--function function (first come)--function (later). After the PK, the warehouse is placed in the following things:
2. Line-wise interpretation of code
After the pre-parsing JS, starting from top to bottom execution code, when executed to fn1 () code, strange things appear, because Fn1 () is called function block, so began the above two processes, parsing-interpretation, Well, after reading it, look at what's changed in the warehouse.
Why is there another one? In this analysis, did not find the emergence of Var ah, a front and no ha, why will more than a? We should not forget that when parsing fn1 (a), where a is the equivalent of FN1 (Var a), so the problem is here, there is more than a var effect, so the above results will occur.
3. Execute the parsed code here
So when the alert (a) is executed, because it was assigned a value of undefined at the time of parsing, the undefined window pops up.
The results after execution are as follows
Take down the execution, alert (a), this time you know the demerit! The pop-up is definitely 1 ha.
Not to be continued
Understandable JavaScript scope (ii)