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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:28:22+00:00 2026-06-12T21:28:22+00:00

Possible Duplicate: Use of ‘prototype’ vs. ‘this’ in Javascript? Advantages of using prototype, vs

  • 0

Possible Duplicate:
Use of ‘prototype’ vs. ‘this’ in Javascript?
Advantages of using prototype, vs defining methods straight in the constructor?

I’m learning about prototype in Javascript. One thing I don’t quite understand is why should I add a function using CONSTRUCTOR_FN.prototype.METHOD_NAME convention rather than just using this.METHOD_NAME in the body of the CONSTRUCTOR?

I have written this little code to clarify:

function Cat ( name ) {
    this._name = name;
    this.say = function ( thing ) {
        alert( this._name + " says: '" + thing + "'" );
    }
}

function Dog ( name ) {
    this._name = name;
}
Dog.prototype.say = function ( thing ) {
    alert( this._name + " says: '" + thing + "'" );
}

var c = new Cat( "Mitt");
var d = new Dog( "Barak" );
c.say( "War" );
d.say( "No war" );

As far as I can see both the Cat and Dog constructors work the same. If I understand from this question correctly, the only difference is that when you add something to the prototype, all objects from that constructor will have it. Is there any other reason?

  • 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-12T21:28:23+00:00Added an answer on June 12, 2026 at 9:28 pm

    Actually yes, there is a difference. When you adding a method or property via prototype you can be sure that this method/property will be created only once and they will be contained in the prototype object. However, if you just add your methods to a function that methods will be cloned with each new instance of your class. Lets say you have 10 object instances from your class. If you use prototype you will have only 1 method for all this 10 instances. And if you added method to a function object itself you will have 10 methods copy.

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

Sidebar

Related Questions

Possible Duplicate: Use of 'prototype' vs. 'this' in Javascript? I went to various websites
Possible Duplicate: Use of 'prototype' vs. 'this' in Javascript? I am confused with these
Possible Duplicate: Use of 'prototype' vs. 'this' in JavaScript? OK, So I am somewhat
Possible Duplicate: Use of 'prototype' vs. 'this' in Javascript? I've seen both these two
Possible Duplicate: Use of var keyword in C# Which one is better? using var
Possible Duplicate: How does JavaScript .prototype work? What is the use of prototype property
Possible Duplicate: Use javascript variable in object name I am using CKeditor as a
Possible Duplicate: Why use getters and setters? Is there any advantage to making methods
Possible Duplicate: JavaScript: Class.method vs. Class.prototype.method What's the difference between creating a prototype like
Possible Duplicate: Cannot use ‘this’ in member initializer? Any ideas why I get an

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.