Skip to content

Instantly share code, notes, and snippets.

@BadBastion
Created October 10, 2015 18:37
Show Gist options
  • Save BadBastion/2a459759a6806ca6d3ef to your computer and use it in GitHub Desktop.
Save BadBastion/2a459759a6806ca6d3ef to your computer and use it in GitHub Desktop.
Javascript getters and setters
var person = {sutff:"stuff"};
Object.defineProperty(person, 'fullName', {
get: function() {
return firstName + ' ' + lastName;
},
set: function(name) {
var words = name.split(' ');
this.firstName = words[0] || '';
this.lastName = words[1] || '';
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment