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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:58:18+00:00 2026-05-29T22:58:18+00:00

Im probably missing the point totally here so apologies. But Im wondering what the

  • 0

Im probably missing the point totally here so apologies. But Im wondering what the difference between using ‘this’ and ‘prototype’ are in this context. And what I should really be using to construct rich classes that are reusable…

I have this…

function MyClass() {

}

MyClass.prototype.name = null;

MyClass.prototype.init = function () {

    console.log('init');

    MyClass.prototype.name = 'Peter set by proto';

    this.name = 'Peter set by this';

};

MyClass.prototype.SayName = function() {

    console.log(MyClass.prototype.name);
    console.log(this.name);
};

And on the page..

<script type="text/javascript">


        var myClass = new MyClass();
        myClass.init();
        myClass.SayName();

    </script>

The output is…

init
Peter set by proto
Peter set by this

So whats the differenve between proto and this I thought they both basically access the object/class…?

  • 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-29T22:58:22+00:00Added an answer on May 29, 2026 at 10:58 pm

    Simplly put, attribute of prototype will appear in all objects of the class, and attribute of the object just belongs to this object.

    you set:

    MyClass.prototype.name = 'Peter set by prototype';
    

    and you console.log:

    console.log(new MyClass().name);
    console.log(new MyClass().name);
    ....
    

    all of them would show ‘Peter set by prototype’.

    and if you set:

    var myClass = new MyClass();
    myClass.name = "Peter set by object";
    

    and you console.log:

    console.log(new MyClass().name);
    console.log(myClass.name);
    ....
    

    would show:

    Peter set by prototype
    Peter set by object

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

Sidebar

Related Questions

I am probably totally missing the point here but.... How can I pass a
This is probably something silly I'm missing but I'm definitely lost. I'm using .NET
Probably missing something completely obvious here, but here goes. I'm starting out with Spring
I'm probably missing out on something fundamental here but it seems rather tricky and
I'm probably missing something obvious here but here's what I'm trying to do. From
This is with SBCL 1.0.55 on Debian squeeze. I'm probably missing something obvious, but
I'm probably missing something easy, but I seem to be blocked here... I have
I think I'm probably just missing something in the docs here, but how do
I feel like I'm missing an obvious point here, but let's say I'm working
I'm probably missing something very basic but I cannot figure out why I get

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.