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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:55:17+00:00 2026-05-22T16:55:17+00:00

I have a basic lack in understanding the OOP for javascript. What I understand

  • 0

I have a basic lack in understanding the OOP for javascript. What I understand is that I can make classes like this

var Car = function(){}

Car.prototype.GetBrand = function(){ return "Ford";}
Car.prototype.GetYear = function(){ return "1989";}

var ford = new Car();

ford.GetBrand();
ford.GetYear();

this works…
Now I want to implement a function GetInfo and this should print out Brand & Date

how can I reference the GetBrand() and GetYear() methods in my GetInfo() method.

  This is not working:
Car.prototype.GetInfo = function(){ 
        return this.GetBrand()+ ' '+ this.GetYear();
    }

this is not the right accessor…
What do I miss here?

OK edit:
this was a simplified example there my realy method call is in anothe function and that’s why we are talking about another scope:

JsonLoader.prototype.GetJsonAndMerge = function(url,template,tagToAppend){
$.ajax({
    url: url,
    dataType: 'json',
    success: function(data) {
        this.ShowItems(data,template,tagToAppend); 
        }
    });
}

I try to reach my ShowItems method… here and this is again in a function that’s maybe why the this operator does not work… sorry for the confusion =/

  • 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-22T16:55:18+00:00Added an answer on May 22, 2026 at 4:55 pm

    You are missing an unintended recursion:

    Car.prototype.GetInfo = function (){  
      return this.GetBrand()+ ' '+ this.GetYear(); // instead of GetInfo() !
    }
    

    Then you can call

    ford.GetInfo() // returns "Ford 1989"
    

    EDIT: The reason to use prototype here is to conserve memory. When you call new Car(), the object gets copied, not “constructed” in the traditional sense. Calling new on

    var Car = function(){
      this.GetBrand = function(){ return "Ford";}
      this.GetYear = function(){ return "1989";}
    }
    

    would also copy the function bodies to every instance. This is why putting a method into the prototype chain makes sense. Also adding a function to already-existing instances only works when adding it to the prototype chain.

    Also note that the convention is to give capital first letters to constructor functions only, so Car is okay, but GetInfo should be getInfo.


    JsonLoader.prototype.GetJsonAndMerge = function(url,template,tagToAppend){
      var self = this;
      $.ajax({
        url: url,
        dataType: 'json',
        success: function(data) {
          self.ShowItems(data,template,tagToAppend); 
          }
        });
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems so basic, I'm flabbergasted for lack of a better word. I have
I have a basic form with controls that are databound to an object implementing
I have a basic understanding of mock and fake objects, but I'm not sure
I have a basic CRUD form that uses PageMethods to update the user details,
I have a basic ActiveRecord model in which i have two fields that i
I have a basic cs-major understanding of multi-threading but have never had to do
I have a basic C# console application that reads a text file (CSV format)
I have a basic quiz/survey type application I'm working on, and I'd like to
I have basic idea about running PHP in different configurations like mod_php, cgi, FastCGI,
Sorry if this is generic in nature, but I have a question that maybe

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.