Last active
September 1, 2015 19:44
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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