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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:12:20+00:00 2026-05-25T22:12:20+00:00

is there an equivalent in javascript to the following C# code public class Class

  • 0

is there an equivalent in javascript to the following C# code

public class Class
{
    public string str
    {
        get;
        set;
    }
}

I am trying to do something like this

    var list = function () {
        this.settings = {
            id: 1
        };
        this.id = //something
    }
    var List = new list();
    alert(List.id); //alerts 1
    List.id = 5; // should set this.settings.id = 5
    alert(List.settings.id); // alerts 5

Although this answer is good for the c# class, I still cant reference the id as follows

    var list = function() {
        this.settings = {
            _id: 0, 
            get id() { return this._id; }, 
            set id(x) { this._id = x; }
        };
        this.id = this.settings.id;
    }

    var List = new list();


    document.write(List.id + "<br />");
    List.id += 10;
    document.write(List.settings.id + "<br />");

which is probably because this.settings.id only passes the value back to this.id and not the actual object

  • 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-25T22:12:21+00:00Added an answer on May 25, 2026 at 10:12 pm
    var o = {
        _p: 5,
        get p() { return this._p; },
        set p(x) { this._p = x; }
    };
    

    Example usage – jsFiddle.net

    Defining Getters and Setters – developer.mozilla.org

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

Sidebar

Related Questions

Is there a JavaScript equivalent of Java 's class.getName() ?
Is there a JavaScript equivalent to .NET's String.IsNullOrWhitespace so that I can check if
Is there an immediate equivalent in javascript for the below jquery code? $('.checkbox').each(function() {
Hi is there an equivalent ruby method to JavaScript encodeURIComponent method? i am using
Is there an equivalent in JavaScript for PHP's reference passing of variables? [PHP]: function
Is there an equivalent for ruby's array[n..m] in JavaScript? For example: >> a =
Is there ASP code which can retrieve the users current language? In javascript I
Are there any equivalent JavaScript functions for Python's urllib.parse.quote() and urllib.parse.unquote() ? The closest
Is there an equivalent of PHP's preg_match_all in Javascript? If not, what would be
Is there any method to captitalize a string in JavaScript? I want a JS

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.