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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:12:18+00:00 2026-05-24T20:12:18+00:00

i found 2 define for property in OOP javascript ,which is correct? define property

  • 0

i found 2 define for property in OOP javascript ,which is correct?

  1. define property inner current object with private field(with var)
  2. define property in prototype object with public field(with this)

i think first is more like to c# property?

  function Pet() {

               this._age = 0;                       //second public feild

               _name = 'm2';                         //first private feild
              this.get_name= function () {          //first define
                    return _name;
                }

                set_name= function (value) {
                    this._name = value;
                }
            }


            Pet.prototype = {
                speak: function () {                        
                    throw Error.notImplemented();
                },

                get_age: function () {          //second define
                    return this._age;
                },
                set_age: function (value) {
                    if (isNaN(value) || value < 0) {
                        throw Error.argument('age');
                    }
                    this._age = 0;
                }
            }

            Pet.registerClass('Pet');

            var pet = new Pet();
            var u = d.get_name();
  • 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-24T20:12:20+00:00Added an answer on May 24, 2026 at 8:12 pm

    first option with var as local vaariable and two getter and setter defines better as property because it give option to control input validation and do custom code when setting value like raiseing event.

    With this keyword, it is again works property but is more like public field.

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

Sidebar

Related Questions

As found here - https://github.com/neave/touch-scroll : (function($) { // Define default scroll settings var
In standard library, I found that namespace std is declared as a macro. #define
I found several posts online stating that I could access my application delegate object
I got these 2 entities: @javax.persistence.Entity public class Book { @javax.persistence.EmbeddedId private BookPK id;
I found myself needing to define some styles and templates for a couple ToggleButton
I just found two piece of code #if CONSOLE // defined by the console
I haven't found similiar post so I'm asking this. Let's say I defined somewhere
Why I get this error? Page not found (404) Using the URLconf defined in
Found some old code, circa VS 2003. Now I have just VS 2008 (SP1)
Found the following in an Oracle-based application that we're migrating (generalized) : SELECT Table1.Category1,

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.