Fantastic js
The Code is as follows:
>>> Function a () {function B () {return "aaa"} Function. prototype. c = function () {return B ();}}
>>> ()
>>> A. c
Function ()
>>> A. c ()
"Aaa"
>>> A. hasOwnProperty ("c ")
False
Look at this code. First, declare a function a and define function B internally. However, function B is not the method of function object, it's just a temporary variable function (or a private function, but I don't know how to describe it) in function a. a function c uses function () is defined later () {} is defined internally in a, so closure is generated. Therefore, c can traverse all the internal block variables under a, including B. I mounted c to Function again. under prototype, a is not directly attached to a, but to the prototype chain of a. It is finally executed, and hasOwnProperty is also false.
Code
The Code is as follows:
>>> D = {};
Object
>>> Function a () {function B () {return "aaa"} d. c = function () {return B ();}}
>>> ()
>>> D. c ()
"Aaa"
Closure has nothing to do with the context of function execution. context can change this using the call apply method. However, closure does not seem to be able to modify the function after the function is defined.