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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:18:47+00:00 2026-05-27T12:18:47+00:00

Possible Duplicate: JavaScript private methods I was kind of busy playing with jquery, Ext

  • 0

Possible Duplicate:
JavaScript private methods

I was kind of busy playing with jquery, Ext JS, …etc. that I never required to do this. So, I doubt if I am right.

The question is:

Create a Person class with public/private/privileged members and methods.

My solution is:

function Person () {
    var privatemember; //I wonder if there is any other way
    this.publicmember = null;
    this.privilegedmember = function (){
        //anything here
    }
}
Person.prototype.sayHi = function(){
    "Hi";
}

Please correct me if I am wrong, also explain individual in detail

Thanks.

  • 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-27T12:18:48+00:00Added an answer on May 27, 2026 at 12:18 pm

    Yes, that is the Javascript way. In truth, there are no “classes” in javascript. Every object is unique. It’s like a dictionary (in other languages) which allows you to create unlimited key/value pairs.

    There is however the prototype mechanism which allows for one object to be a “prototype” for another object. In this case, if a property is not found on the original object, then the prototype is searched for that property (and the prototype’s prototype, etc.) But both objects are still individual and unique. This is nothing like the “class” mechanism found in C++ derived languages (like Java or C#), and attempting to emulate that will bring you many headaches.

    Also yes, there is also nothing like the private/public/protected members. Your approach is correct – you can get hidden data by using closures. This enables something similar to “private” and “public”. Unfortunately there is nothing to emulate the “protected” level (accessible only by this object and those for whom it is a prototype).

    This brings to memory an interesting video about Javascript performance. The guys there had found out that (at least in the case of web browsers) the sheer amount of Javascript code can pretty quickly become a performance limiting factor. So it’s often better to just make most of your variables public than to go with the OOP mantra of “private member – public accesors”. It’s less code and thus faster.

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

Sidebar

Related Questions

Possible Duplicate: javascript: pause setTimeout(); Im using jQuery and working on a notification system
Possible Duplicate: Javascript regex returning true.. then false.. then true.. etc var r =
Possible Duplicate: JavaScript scope and closure What is this for? (function(){ //The code to
Possible Duplicate: javascript (jquery) calendar plugin I am going to develop the weekly calendar
Possible Duplicate: Javascript - array.contains(obj) What's wrong with this: var zipCodes =(['90001','90002','90003']); Test if
Possible Duplicate: Is JavaScript’s math broken? This seems really stupid, but when running this,
Possible Duplicate: Javascript swap array elements I have a array like this: this.myArray =
Possible Duplicate: JavaScript function aliasing doesn't seem to work Why doesn't this work? function
Possible Duplicate: JavaScript: formatting number with exactly two decimals Maybe I'm going about this
Possible Duplicate: Javascript library: to obfuscate or not to obfuscate - that is the

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.