Javascript array named status not working in google chrome

This question already has an answer here:

  • Simple Javascript array initialization not working in Chrome 2 answers
  • How do JavaScript closures work? 88 answers

  • This issue is already answered here.

    <html>
        <body>
            <script>
                function test(){
                    var array = [1, 2, 3];
                    document.write("Type of [" + array + "] : " + (typeof array) + "<br />");
                    document.write("Value of array.length : " + array.length + "<br />");
    
                    document.write("<br /><br />");
    
                    var status = [1, 2, 3];
                    document.write("Type of [" + status + "] : " + (typeof status) + "<br />");
                    document.write("Value of status.length : " + status.length + "<br />");
                }
    
                test();
                </script>
        </body>
    </html>
    

    If you try the above given code it works as expected because the scope of the variable status is limited to the local scope of the method status. In your sample the scope of the variable was global(scope is window).


    The problem is that in Chrome, window (the global object) has a status property, which for some reason Chrome seems to be referring to instead of your status var. Renaming status to anything else, say, myStatus , will give you the results you expect.


    在JavaScript中,我认为你想要:

    var array = new Array(1, 2, 3);
    
    链接地址: http://www.djcxy.com/p/1490.html

    上一篇: 解释IIFE内部循环

    下一篇: Javascript数组命名状态不适用于谷歌浏览器