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 6867355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:17:57+00:00 2026-05-27T03:17:57+00:00

I am a bit confused about the usage of prototypes in Javascript. Let’s take

  • 0

I am a bit confused about the usage of prototypes in Javascript.

Let’s take the following example:

(1)

   function Rectangle(w, h) { 
      this.width=w; 
      this.height=h; 
      this.area=function() { this.width * this.height; }
   }

And a similar case where the area is attached to a prototype as follows:

(2)

   function Rectangle(w, h) { 
      this.width=w; 
      this.height=h; 
   }
   Rectangle.prototype.area=function() { this.width * this.height; }
  • What is the diffrence between (1) and (2) ?
  • When would you use (1) or (2) for writing methods on classes?
  • 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-05-27T03:17:58+00:00Added an answer on May 27, 2026 at 3:17 am

    prototypes are best shown differently.

    function rectangle(w, h) {
        var rect = {};
        rect.width=w; 
        rect.height=h; 
        rect.area=function() { return this.width * this.height; };
        return rect;
    }
    

    vs

    var Rectangle = {
        area: function() { return this.width * this.height; }
    }
    
    function rectangle(w, h) {
        var rect = Object.create(Rectangle);
        rect.width=w; 
        rect.height=h; 
        return rect;
    }
    

    The idea is simple, you put common stuff on a prototype object and you then inherit from it.

    As for when you want to use the prototype? Always.

    Of course you probably want to Improve ES5 OO with sugar

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

Sidebar

Related Questions

I am a bit confused about this function definition in Prolog: sample(X,[X|Tail]) :- member(X,Tail).
I am a bit confused about this. If you're building a distributed application, which
I'm a bit confused about mvc terminology. Using the question title as an example,
I'm a bit confused about the usage of Abstract classes in C#. In C++,
I am a bit confused about this piece of code. public static void Foo(A
I'm a little bit confused about how to approach this. I had never used
I am bit confused about the difference between the usage of std::remove algorithm. Specifically
This might be a very basic question, but I am a bit confused about
I am a bit confused about the usage of cudaEvent_t . Currently, I am
I'm a bit confused about proper usage of svn in case of a single

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.