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
Example usage – jsFiddle.net
Defining Getters and Setters – developer.mozilla.org