The value of the self-executing anonymous function is stored in the variable prison inside var prison = (function () { var prisoner_name = ' wangming ', jail_term = ' year term ';
//self-executing anonymous function returns an object on which the property is exactly what we want to return { prisoner:prisoner_name + '-' + jail_term, sentence:jail_term };}) ();//Prison.prisoner_name undefined because it is not a property console.log (Prison.prisoner_name) on the return object of the self-executing anonymous function;//Prison.jail_ Term is undefined because it is not a property on the object returned by the self-executing anonymous function//outputs Undefinedconsole.log (prison.jail_term); Prison is an object so you can still define the Jail_term property on it ... prison.jail_term = ' sentence commuted ';//... But Prison.prisoner is still not updated console.log (prison.jail_term);//This outputs ' WangMing-20 year term ' console.log ( Prison.prisoner);//This outputs ' the term ' console.log (prison.sentence);/* Prison.prisoner has not been updated for several reasons. 1. Jail_term is not a property on an prison object or prototype, it is an object variable created in the execution environment, the prison variable holds the variable, and the execution environment is no longer present because the function has finished executing. 2. These properties are set only once for anonymous function execution and are never updated. To be able to update them, we have to turn attributes into methods, and each time we call them we will access the variables. */
Module Mode-Property-to-method comprehension