猿问

为什么打印的结果this.a不是10

       function f1() {

            this.a = 1;

            this.b = [1, 2, this.a];

            this.show = function(){

                console.log(this.b)

            }

        }


        function f2() {

            this.a = 2;

        }


        f2.prototype = new f1();


        var a2 = new f2();

        a2.a = 10;

        console.log(a2.show()); //[1,2,1]?


拉莫斯之舞
浏览 676回答 2
2回答

米琪卡哇伊

数组存的不是变量var a = [], b = 1;a[0] = b;console.log(a);//[1]b = 2;console.log(a); //[1]
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答