Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8649695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:37:25+00:00 2026-06-12T13:37:25+00:00

I set the prototype of Array as an instance of my , I think

  • 0

I set the prototype of Array as an instance of my, I think book.aa will display "aa", but it displays "undefined", why? Thanks!

   <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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:37:26+00:00Added an answer on June 12, 2026 at 1:37 pm

    You cannot assign to Array.prototype because prototype is a read-only property of Array.

    So when you write

    Array.prototype = new my();
    

    nothing happens. To see why, try

    JSON.stringify(Object.getOwnPropertyDescriptor(Array, "prototype"))
    

    The result is

    "{"value":[],"writable":false,"enumerable":false,"configurable":false}"
    

    Unless you are in strict mode, the assignment silently fails.

    That’s why — and see http://jsfiddle.net/5Ysub/ — if you execute

    function my() {
        this.aa = 'aa';
    }
    Array.prototype = new my();
    Array.prototype.bb = "bb";
    var book = new Array();
    book[0] = "War and Peace";
    document.write(book.aa+book.bb);
    

    You get

    undefinedbb
    

    The bb works because you have assigned to the real Array.prototype when you created and set the bb property.

    It is a good thing that Array.prototype cannot be whacked, IMHO. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if the title is misleading, but I really couldn't think of anything better.
I am learning about JS Prototype. If I set a prototype of a constructor(A)
I've set up a very simple prototype to test out the YUI Uploader. (flash
I am essentially trying to set a function's prototype within the function itself. The
I'm trying to add a method to the Event prototype. In order to call/set
How to set the value of an array from a function? The issue is
What I got is a TableView which is using Prototype Cells and an array
I need to load an array of images in Javascript, but I want to
Prototype is great, but with the 1.6.1 release, the library still doesn't allow getting/setting
I'm trying to set properties of some elements through a for loop, but am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.