相关疑难解决方法(0)

为什么我不能覆盖`Array`(`Array.prototype`)的原型?

我将原型设置Array为一个实例my,我认为book.aa会显示"aa",但它显示"undefined",为什么?谢谢!

   <html>
    <head>
        <title>Array Properties</title>
        <h2>Array Properties</h2>
        <script type="text/javascript">
            function my() {
                this.aa = 'aa';
            }
            Array.prototype = new my();
            Array.prototype.bb = "bb";
            var book = new Array();  
            book[0] = "War and Peace";  

        </script>
    </head>
    <body bgcolor="lightblue">
        <script type="text/javascript">
            document.write(book.aa+book.bb);
        </script>
    </body>

    </html>
Run Code Online (Sandbox Code Playgroud)

javascript

5
推荐指数
1
解决办法
2221
查看次数

标签 统计

javascript ×1