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

  • SEARCH
  • Home
  • 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 8112707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:35:42+00:00 2026-06-06T02:35:42+00:00

In prototypal languages object can basically clone each other. So, lets say we have

  • 0

In prototypal languages object can basically clone each other.

So, lets say we have a constructor function:

Bla = function()
{
    this.a = 1;
}

I can create a new instance of that object like this: x = new Bla();. Now, x.a returns 1.

If I were to write Bla.prototype.b = 2, then x.b would return 2. But, why? If x "cloned" Bla, why can’t I just say that Bla.b = 2, without referencing the Bla.prototype, and still get the same functionality? Does this have something to do with the this keyword?

  • 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-06T02:35:44+00:00Added an answer on June 6, 2026 at 2:35 am

    ECMAScript (JavaScript) supports "prototype-based inheritance". This means there is no differentiation between "class" and "instance" in JS.

    Opposed to OOP in other languages, in JS a "class" and "instance" are basically the same thing:

    When you define Something, it is instanciated immediately (ready to use), but can also serve as a "prototype" to clone the initial(!) definition of the object Someting for another instance with the same properties and methods.

    In ECMAScript, everything is an object, even the objects initial definition. In other OOP languages, you have a "class" for the definition part.

    The prototype object is for the case when you want to extend the prototype of "Something" (read: "class" Something) after the initial definition and add the new property / function to all current and future instances of Something.

    If you are confused now, i think this code example may help to spot the difference:

    // when defining "Something", the initial definition is copied into the "prototype"
    var Something = function()
    {
        this.a = 1;
    }
    // we can either modify the "prototype" of "Something"
    Something.prototype.b = 2;
    // or we can modify the instance of "Something"
    Something.c = 3;
    
    // now lets experiment with this..
    
    var x = new Something();   // read: "clone the prototype of 'Something' into variable 'x'"  
    
    console.log(x.b);    // logs "2"  -- "b" was added to the prototype, available to all instances
    
    console.log(x.c);    // undefined   -- "c" only exists in the instance "Something"
    console.log(Something.c);  // logs "3"  -- "Something" is an object, just like our new instance 'x'
    
    // also note this:
    Something.a = 1337;
    var y = new Something();
    console.log(y.a);    // logs "1"  -- because the "prototype" was cloned, 
                         // opposed to the current state of object "Something"
    console.log(Something.a);  // logs "1337" 
    

    As you see in the last example, the concept of "prototype" is necessary to avoid cloning the current "state" of your object.

    If it wouldn’t be implemented this way, you would possibly end up with weird effects, because if the original object "Something" was used / modified before you clone it, then the current state would be copied as well. That is why the language designers went for the prototype construct.

    Always remember: "Something" isn’t a static definition, like "classes" are in other OOP languages.


    The ECMAScript specification says about prototype:

    A prototype is an object used to implement structure, state, and behaviour inheritance in ECMAScript. When a constructor creates an object, that object implicitly references the constructor’s associated prototype for the purpose of resolving property references. The constructor’s associated prototype can be referenced by the program expression constructor.prototype, and properties added to an object’s prototype are shared, through inheritance, by all objects sharing the prototype.

    Some JS frameworks like the equally named "prototype" make heavy use of this feature to extend the functionality of Javascripts built-in objects.

    For example, it extends the native array object with the method forEach, to add this missing feature to JS:

    Array.prototype.forEach = function each(iterator, context) {
      for (var i = 0, length = this.length >>> 0; i < length; i++) {
        if (i in this) iterator.call(context, this[i], i, this);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this very familiar model of prototypal construction: function Rectangle(w,h) { this.width = w;
I'm new to prototype-based languages and have read this question: Preserving a reference to
I come from classes object orientation languages and recently I have been learning those
I have a hierarchy of classes, and I'd like that each object had an
I have some object, say son , which I'd like to inherit from another
I've been wondering about JavaScript's prototypal nature, and the benefits of it, and have
I have read through some tutorials about javascript prototypal inheritance patterns but I am
I have a bunch of methods that make use of jquery to basically generate
I realize this has been asked hundreds of times, however, I can't seem to
I'm learning JS prototypes. From Java language point I expect,that SpecificRectangle object will have

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.