Problems related to local variables in javascript.

        function Person(){}                                    
        
        var person = new Person();//Person
        function fun(){
            var index = 0;
            //personsay
            person.run = function(){
                console.log(PPindex);//index
            }
        }
        
        fun();//fun
        //5personrun
        for (var i = 0;i < 5;iPP) {
            person.run();//12345
        }
    :funindexpersonrunindex

May.24,2021

this is a closure.
when you add a function to person.run , the variable in function is not destroyed, even if it is a variable of an external function.


this is a closure.
gives you an address to learn:
https://developer.mozilla.org. https://developer.mozilla.org.


internal function, referencing the variables of the external function.
about closures: JavaScript scope and closure


references to the person.run function have not disappeared

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3720b-405f7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3720b-405f7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?