Application of the function:
1<! DOCTYPE html>234<meta charset= "UTF-8" >5<title>Document</title>67<body>8<script>9 functionf () {TenAlert This. x); One } A varx = 1; - varA = { -X:2 the } -A.F2 =F; - varCC =a.f2 () - Console.log (cc) +</script> -</body> +You guess what CC is, is 2;
Let's look at an example:
1<! DOCTYPE html>234<meta charset= "UTF-8" >5<title>Document</title>67<body>8<script>9 Ten varx = 1; One varA = { AX:2, -Fn:function() { - return( This. x) the } - } - varb = { -X:3 + } -Q =A.fn (); +p =A.fn; AQ1 =p (); atB.F2 =A.fn; -Q3 =b.f2 (); -Q5 =( b.f2) (); -D =B.f2; -Q4 =d (); -Console.log ("q" + "~ ~ ~ ~" +q) inConsole.log ("Q1" + "~ ~ ~ ~" +Q1) -Console.log ("Q3" + "~ ~ ~ ~" +Q3) toConsole.log ("Q4" + "~ ~ ~ ~" +Q4) +Console.log ("Q5" + "~ ~ ~ ~" +Q5) -</script> the</body> *Note that Q3 and Q5 are the same results;
JavaScript tip 1