Skip to content

Instantly share code, notes, and snippets.

@kdarty
Last active September 1, 2015 19:44
Show Gist options
  • Save kdarty/1a61c2411fdee97d9e4d to your computer and use it in GitHub Desktop.
Save kdarty/1a61c2411fdee97d9e4d to your computer and use it in GitHub Desktop.
Object Oriented JavaScript with Getters and Setters for Properties. This is but just one example that seems rather friendly and straight forward. #OOP
var Person = new function () {
var _firstName = null;
var _lastName = null;
// Public Properties
this.FirstName = {
get: function () {
return _firstName;
},
set: function (value) {
_firstName = value;
}
};
this.LastName = {
get: function () {
return _lastName;
},
set: function (value) {
_lastName = value;
}
};
};
// Set First and Last Name Properties
Person.FirstName.set('John');
Person.LastName.set('Doe');
// Display Full Name
alert(Person.FirstName.get() + " " + Person.LastName.get());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment